C#完成開機主動啟動設置代碼分享。本站提示廣大學習愛好者:(C#完成開機主動啟動設置代碼分享)文章只能為提供參考,不一定能成為您想要的結果。以下是C#完成開機主動啟動設置代碼分享正文
/// <summary> /// 設置法式開機啟動 /// 或撤消開機啟動 /// </summary> /// <param name="started">設置開機啟動,或許撤消開機啟動</param> /// <param name="exeName">注冊表中法式的名字</param> /// <param name="path">開機啟動的法式途徑</param> /// <returns>開啟或則停用能否勝利</returns> public static bool runWhenStart(bool started, string exeName, string path) { RegistryKey key = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);//翻開注冊表子項 if (key == null)//假如該項不存在的話,則創立該子項 { key = Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"); } if (started == true) { try { key.SetValue(exeName, path);//設置為開機啟動 key.Close(); } catch { return false; } } else { try { key.DeleteValue(exeName);//撤消開機啟動 key.Close(); } catch { return false; } } return true; }