C#設置開機啟動項、撤消開機啟動項。本站提示廣大學習愛好者:(C#設置開機啟動項、撤消開機啟動項)文章只能為提供參考,不一定能成為您想要的結果。以下是C#設置開機啟動項、撤消開機啟動項正文
假如想你寫的法式隨體系開機一路啟動的話,那末你可以照上面這個辦法來做。
RunWhenStart(false, Application.ProductName, Application.StartupPath + @\"\\MUS.exe\");
/// <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);
}
} [Page]
else
{
try
{
Run.DeleteValue(name);
HKLM.Close();
}
catch (Exception)
{
//
}
}
}