从注册表C#获取参数

时间:2015-05-05 05:57:15

标签: c# winforms arguments registry

我在注册表中设置键值如下 -

 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中读取参数。

任何帮助?

1 个答案:

答案 0 :(得分:0)

为什么使用百分号(%)?请尝试[空格]:

registryKey.SetValue("MobiCheckerTest", "\"" + Application.ExecutablePath + "\" autostart");
相关问题