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 下就可以看到已经被写入注册表,这样在开机时就会自动开启程序的。
  • 相关阅读:
    office(PPT、Word、Excel)功能目录
    《数商》笔记
    笔记模板
    如何运用思维导图安排考生读书计划(增订版)
    自制桌面图片
    selenium+AutoIt
    selenium中应用问题解决
    mysql卸载
    vue每次修改刷新当前子组件
    vue与dajngo
  • 原文地址:https://www.cnblogs.com/059212315/p/2371812.html
Copyright © 2011-2022 走看看