读书人

C#设立写注册表设置程序开机启动

发布时间: 2012-09-07 10:38:15 作者: rapoo

C#设置写注册表,设置程序开机启动

//打开开机启动        private void SetAutoStart()        {            string strPath = Application.ExecutablePath;            RegistryKey loca = Registry.LocalMachine;            try            {                RegistryKey run = loca.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");                if (run.GetValue("裂帛客服工具") == null)                {                    run.SetValue("程序名称或任意值", strPath);                }            }            catch (Exception)            {                ShowMessageOnUI.ShowErrorMessage("打开开机启动设置失败!");            }            finally            {                loca.Close();            }        }        //关闭开机启动        private void SetNotAutoSatrt()        {            RegistryKey loca = Registry.LocalMachine;            try            {                RegistryKey run = loca.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");                if (run.GetValue("裂帛客服工具") != null)                {                    run.DeleteValue("程序名称或任意值");                }            }            catch (Exception)            {                ShowMessageOnUI.ShowErrorMessage("关闭开机启动设置失败!");            }            finally            {                loca.Close();            }        }

?

读书人网 >C#

热点推荐