C# 程序開機啟動
/// <summary> /// 開機啟動項 /// </summary> /// <param name=\"Started\">是否啟動</param> /// <param name=\"name\">啟動值的名稱</param> /// <param name=\"path\">啟動程序的路徑</param> public static void RunWhenStart(bool Started, string name, string path) { RegistryKey HKLM = Registry.LocalMachine; RegistryKey Run = HKLM.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run"); if (Started == true) { try { Run.SetValue(name, path); HKLM.Close(); } catch (Exception Err) { MessageBox.Show(Err.Message.ToString(), "MUS", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { try { Run.DeleteValue(name); HKLM.Close(); } catch (Exception) { // } } }
取得程序名稱: Application.ProductName,
取得程序路徑: Application.StartupPath +"\\"+"你的程序.exe";
最後更新:2017-04-02 16:47:59