Start application with parameter in a shortcut.  
Author Message
Tobbe2





PostPosted: Visual C# Language, Start application with parameter in a shortcut. Top

Hi,

I'm trying to find out a way to start my C# application with a parameter (e.g. "c:\program files\applikation.exe /parameter") in a shortcut and the application should detect the parameter and use it differently from when I start it without the parameter.

Is there a way to do so

Regards
Tobbe



Visual C#20  
 
 
Dah_cn





PostPosted: Visual C# Language, Start application with parameter in a shortcut. Top

Every application got a Main method. You can access the parameters from the Main method. The Main Method is defined as : " static void Main(string[] args)", and the "args" is the parameter strings' array.

e.g. "c:\program files\applikation.exe /parameter"

So you can't use these code to determine where the application go:

static void Main(string[] args)

{

if(args.Length > 0)

{

if(args[0] == "/parameter") { /* Do things */ }

}

else { /* Do things if without parameters*/ }

}



 
 
Andrey Kutovets





PostPosted: Visual C# Language, Start application with parameter in a shortcut. Top

another way is to use GetCommandLineArgs() method from Envoriment



 
 
Tobbe2





PostPosted: Visual C# Language, Start application with parameter in a shortcut. Top

Thank for your help. I'll try this suggestion from you.

Regards
Tobbe


 
 
Tobbe2





PostPosted: Visual C# Language, Start application with parameter in a shortcut. Top

Thanks

Regards
Tobbe