2015-05-05 53 views
0

我設置註冊表的鍵值如下 -從註冊表獲得C#

RegistryKey registryKey = Registry.CurrentUser.OpenSubKey 
       ("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); 


    registryKey.SetValue("MobiCheckerTest", Application.ExecutablePath + "%autostart"); 

註冊表參數看起來喜歡 -

C:\Users\skpaul\Desktop\StartupApp\StartupApp\bin\Debug\StartupApp.EXE%autostart 

在Program.cs的

static void Main(string[] args) //args= string[0]. 
    { 
     Program.LaunchedViaStartup = args != null && args.Any(arg => arg.Equals("autostart", StringComparison.CurrentCultureIgnoreCase)); 

     Application.EnableVisualStyles(); 
     Application.SetCompatibleTextRenderingDefault(false); 
     Application.Run(new Form1()); 
    } 

Form1上。 cs

public Form1() 
    { 
     InitializeComponent(); 
     MessageBox.Show(this, string.Format("Lanched Via Startup Arg:{0}", Program.LaunchedViaStartup)); 
    } 

無法在program.cs中讀取參數。

任何幫助?

回答

0

爲什麼使用百分號(%)符號?嘗試一個[空格]代替:

registryKey.SetValue("MobiCheckerTest", "\"" + Application.ExecutablePath + "\" autostart");