2015-05-05 90 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");