本文實例講述了C#設置軟件開機自動運行的方法。分享給大家供大家參考,具體如下:
#region/// <summary>/// 開機啟動項/// </summary>/// <param name="Started">是否啟動</param>/// <param name="name">啟動值的名稱</param>/// <param name="path">啟動程序的路徑 Application.ExecutablePath</param>public static void RunWhenStart(bool Started, string name, string path){  Microsoft.Win32.RegistryKey HKLM = Microsoft.Win32.Registry.LocalMachine;  Microsoft.Win32.RegistryKey Run = HKLM.CreateSubKey(@"SOFTWARE/Microsoft/Windows/CurrentVersion/Run");  if (Started == true)  {    try    {      Run.SetValue(name, path);      HKLM.Close();    }    catch { }  }  else  {    try    {      Run.DeleteValue(name);      HKLM.Close();    }    catch { }  }}#endregion希望本文所述對大家C#程序設計有所幫助。
新聞熱點
疑難解答