程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> c#設置軟件開機自動運行,修改注冊表

c#設置軟件開機自動運行,修改注冊表

編輯:C#入門知識

[csharp] 
#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 

        #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

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved