1

I have been wondering how to provide command line arguments to a application on startup.
I mean what to type in the code, so that a registry entry is created which supplies the command line args:- I have been using the following code, to create a registry entry(so that application launches on startup.

    using Microsoft.Win32;
    private void SetStartup()
    {
        RegistryKey rk = Registry.CurrentUser.OpenSubKey
        ("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
         rk.SetValue(AppName, Application.ExecutablePath.ToString());           

}

Can anyone tell me what parameter I should modify in

    rk.SetValue() 

function's arguments to supply command line arguements to my app.

Pratik Singhal
  • 6,283
  • 10
  • 55
  • 97

2 Answers2

4

If I understund correct you want add command line arguments when your application startup on windows boot?

Then you must do something like that:

string cmd = Application.ExecutablePath.ToString() + " /arg1 /arg2 /arg3 .....";
RegistryKey rk = Registry.CurrentUser.OpenSubKey
        ("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
         rk.SetValue(AppName, cmd); 
0

You can use: Project Properties--> Debug-->Command Line Argument, then use these arguments from args in Main(string[] args)

PKV
  • 773
  • 1
  • 7
  • 17