1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > C#操作开机自启动(写进注册表)

C#操作开机自启动(写进注册表)

时间:2021-05-07 23:10:25

相关推荐

C#操作开机自启动(写进注册表)

/// <summary>/// 开机自启动/// </summary>/// <param name="fileName">文件路径</param>/// <param name="isAutoRun">是否自启动</param>public void SetAutoRun(string fileName, bool isAutoRun){RegistryKey reg = null;try{if (!System.IO.File.Exists(fileName)){ShowInformation("开机自启动未找到应用程序位置\n", Color.Red);}String name = "PowerControl";reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);if (reg == null){reg = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");//reg = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");}if (isAutoRun){reg.SetValue(name, fileName);}else{reg.SetValue(name, false);}}catch (Exception e){MessageBox.Show(e.ToString());ShowInformation("注册表写入开机自启动异常\n", Color.Red);}finally{if (reg != null)reg.Close();}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。