日期:2014-05-18  浏览次数:20986 次

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();
            }
        }

?