zoukankan      html  css  js  c++  java
  • WinForm程序开机自动启动

    void AutoStart()
            {
                try
                {
                    string regPath = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
                    string path = Application.ExecutablePath.ToLower(); //将当前程序起动路径  
                    //MessageBox.Show(path);
                    string name = System.IO.Path.GetFileName(path);  //获得应用程序名称  
                    //MessageBox.Show(name);
                    var regKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regPath, true);
                    if (regKey == null) regKey = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(regPath);
                    regKey.SetValue(name, path);
                }
                catch
                {
                }
            }

    以上是程序中直接写入注册表,可以在打开运行,输入:regedit 然后找到 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run 下就可以看到已经被写入注册表,这样在开机时就会自动开启程序的。
  • 相关阅读:
    6 完全平方数相关
    5 三位数,每个位置不同
    Neo4j Admin Import 导入多个node和relationship
    Rust所有权
    Rust 多态
    Rust 泛型
    Rust trait
    Rust模块化
    Spring Cloud(Dalston.SR1)
    git 速度慢问题解决
  • 原文地址:https://www.cnblogs.com/059212315/p/2371812.html
Copyright © 2011-2022 走看看