C# Winform 开机自动启动

来源:互联网 发布:云计算ppt模板免费 编辑:程序博客网 时间:2024/05/18 03:19

From:http://write.blog.csdn.net/postedit

 

       /// <summary>       /// 设置开机自动启用        /// </summary>         private void SetAutoStart()        {            try            {                string regPath = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";                string path = Application.ExecutablePath.ToLower(); //将当前程序起动路径                string name = Path.GetFileName(path);  //获得应用程序名称                var regKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(regPath, true);                if (regKey == null) regKey = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(regPath);                regKey.SetValue(name, path);            }            catch            {             }        }

0 0
原创粉丝点击