開機啓動方法:
#region
///<summary>
/// 開機啓動項
///</summary>
/// <paramname="Started">是否啓動</param>
/// <paramname="name">啓動值的名稱</param>
/// <paramname="path">啓動程序的路徑Application.ExecutablePath</param>
public static void RunWhenStart(bool Started,string name, string path)
{
RegistryKey HKLM = Registry.LocalMachine;
RegistryKey aimdir =HKLM.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
if(Started == true)
{
try
{
aimdir.SetValue(name, path);
HKLM.Close();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
else
{
try
{
aimdir.DeleteValue(name);
HKLM.Close();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
Console.WriteLine("1");
}
#endregion
修改註冊表提示權限不足,無法寫入
1、右鍵項目選擇添加
文件夾中文件名
2、修改文件屬性
asInvoker"uiAccess="false" />
↓
requireAdministrator" uiAccess="false" />