Question on shortcuts parameters
Hey. I noticed that some files when they have a shortcut made for them in the target box they have special parameters after the exe file. Like for example: "C:\Program Files\Google\Google Earth\GoogleEarth.exe" -setOGL".
So I'm assuming that that tells google earth to run a special method when it opens it. How can I incorporate that into my programs?
Thanks
John
Re: Question on shortcuts parameters
By using the Environment.GetCommandLineArgs() in your apps form_load and reacting based upon which arguments are passed.
Re: Question on shortcuts parameters
ok so what should i do to write an if statement with it to compare the results.. what would some code look like
Re: Question on shortcuts parameters
It would look like this...
Also, you can test your arguments by going to the Project > Project Properties > Configuration Properties > Debugging > Start Options > Commandline Arguments. Then enter some arguments for your app for testing.
VB Code:
Dim args() As String = Environment.GetCommandLineArgs()
For Each arg As String In args
MessageBox.Show(arg)
Next
Re: Question on shortcuts parameters
hmm I see how it works, but I'm still having trouble getting it to work. Like I put the code in and I can get it to print out the args and everything, but heres what I need it to do:
if the application is run with NO args, then I want it to just run. But if the application is run with the -safe arg then it does something else. I'm having trouble differentiating be tween the number of args and I keep getting index our of array error. Any help?
Re: Question on shortcuts parameters
Test the Length of the array. If it's 1 then there are no command line arguments as the first element is always the executable path itself. If it's greater than 1 then examine each subsequent element to see if one of them is "-safe", or even easier:
VB Code:
If Array.IndexOf(Environment.GetCommandLineArgs(), "-safe") <> -1 Then
'Startup in safe mode.
End If
If you need to use the argument array more than once then you'd assign it to a variable so you didn't have to retrieve it multiple times, but if there is only one possible valid argument then this will work fine.