Winform設定開機啟動-操作登錄檔

yuejin發表於2013-11-27
#region 設定開機執行
/// <summary>
/// 設定開機執行
/// </summary>
/// <param name="R_startPath">需要執行的程式.exe</param>
/// <returns></returns>
public static bool SetStartRun(string R_startPath)
{
     if (!File.Exists(R_startPath))
          return false;
     FileInfo fi = new FileInfo(R_startPath);
     string newName = fi.Name;
     RegistryKey Rkey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
     if (Rkey == null)
          Rkey = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
     Rkey.SetValue(newName, R_startPath);
     Rkey.Close();
     return true;
}
#endregion

 說明:

1、需要給winform軟體管理員許可權

2、R_startPath為:winfrom軟體exe檔案的完整路徑

相關文章