/// <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();}}
1500字范文,内容丰富有趣,写作好帮手!