tags:

views:

69

answers:

2

Is there a way for a Windows Forms application to detect if any flags have been added to the command/shortcut used to launch it? Like if I wanted to go "app.exe /flag", can I get the "/flag" somewhere programatically?

+3  A: 

You can use Environment.GetCommandLineArgs() to get an array of the arguments passed into your program.

Dan Walker
I knew it'd be something stupidly obvious. Thanks!
A: 

Another approach is to handle the Application Startup event where you'll have access to the StartupEventArgs which has a property called CommandLine which is a read-only collection of the command-line arguments.

Rob Sobers