网站icp,菏泽营销网站建设,网站建设header,合肥网页设计培训机构/// /// 将本程序设为开启自启/// /// 自启开关/// private bool SetMeStart(bool onOff){return SelfRunning(onOff, appName, appPath);}/// /// 判断注册键值对是否存在#xff0c;即是否处于开机启动状态/// /// 键值名/// private static bool IsExistKey(string keyName…/// /// 将本程序设为开启自启/// /// 自启开关/// private bool SetMeStart(bool onOff){return SelfRunning(onOff, appName, appPath);}/// /// 判断注册键值对是否存在即是否处于开机启动状态/// /// 键值名/// private static bool IsExistKey(string keyName){try{RegistryKey local Registry.LocalMachine;RegistryKey runs local.OpenSubKey(SOFTWARE\Microsoft\Windows\CurrentVersion\Run, true);string[] runsName runs.GetValueNames();foreach (string strName in runsName){if (strName.ToUpper() keyName.ToUpper()){return true;}}return false;}catch{return false;}}/// /// 写入或删除注册表键值对,即设为开机启动或开机不启动/// /// 是否开机启动/// 应用程序名/// 应用程序路径带程序名/// private static bool SelfRunning(bool isStart, string exeName, string path){try{RegistryKey local Registry.LocalMachine;RegistryKey key local.OpenSubKey(SOFTWARE\Microsoft\Windows\CurrentVersion\Run, true);if (key null){local.CreateSubKey(SOFTWARE//Microsoft//Windows//CurrentVersion//Run);}//若开机自启动则添加键值对if (isStart){key.SetValue(exeName, path);}else//否则删除键值对{key.DeleteValue(exeName);}key.Close();}catch (Exception ex){MessageBox.Show(ex.Message);return false;}return true;}private void Form1_FormClosing(object sender, FormClosingEventArgs e){HideMainForm();e.Cancel true;}厉害开机自启我也在学.NET