Passing command line arguments in C#

Posted by Mark on Stack Overflow See other posts from Stack Overflow or by Mark
Published on 2009-03-17T09:45:43Z Indexed on 2010/05/05 10:58 UTC
Read the original article Hit count: 105

Filed under:

Hi,

I'm trying to pass command line arguments to C# application, but I have problem passing something like this:

"C:\Documents and Settings\All Users\Start Menu\Programs\App name"

even if I add " " to the argument?

Any help??

Here is the code:

    public ObjectModel(String[] args)
    {
        if (args.Length == 0) return; //no command line arg.
        //System.Windows.Forms.MessageBox.Show(args.Length.ToString());
        //System.Windows.Forms.MessageBox.Show(args[0]);
        //System.Windows.Forms.MessageBox.Show(args[1]);
        //System.Windows.Forms.MessageBox.Show(args[2]);
        //System.Windows.Forms.MessageBox.Show(args[3]);
        if (args.Length == 3)
        {
            try
            {
                RemoveInstalledFolder(args[0]);
                RemoveUserAccount(args[1]);
                RemoveShortCutFolder(args[2]);
                RemoveRegistryEntry();
            }
            catch (Exception e)
            {
            }
        }
        }

And here is what I'm passing:

C:\WINDOWS\Uninstaller.exe "C:\Program Files\Application name\" "username" "C:\Documents and Settings\All Users\Start Menu\Programs\application name"

The problem is:

I can get the first and the second args correct, but the last one it gets like this: C:\Documents

© Stack Overflow or respective owner

Related posts about c#