winform窗体应用程序,实现开机自启动代码

来源:互联网 发布:淘宝海报怎么做 编辑:程序博客网 时间:2024/05/17 06:00
public static void SetAutoStart()
        {
            try
            {
                string strAssName = Application.StartupPath + @"\" + Application.ProductName + @".exe";
                string strShortFileName = Application.ProductName;
                RegistryKey sunwatt = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
                if (sunwatt == null)
                {
                    sunwatt = Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
                }

                sunwatt.SetValue(strShortFileName, strAssName);
            }
            catch (Exception)
            {
               
             
            }
          
         
        }


切记在运行VS2010的时候要一定要以管理员身份运行;
0 0
原创粉丝点击