|
-
Jan 14th, 2006, 11:40 AM
#1
Thread Starter
Addicted Member
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
-
Jan 14th, 2006, 11:47 AM
#2
Re: Question on shortcuts parameters
By using the Environment.GetCommandLineArgs() in your apps form_load and reacting based upon which arguments are passed.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 14th, 2006, 12:04 PM
#3
Thread Starter
Addicted Member
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
-
Jan 14th, 2006, 12:08 PM
#4
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
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 14th, 2006, 03:35 PM
#5
Thread Starter
Addicted Member
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?
-
Jan 14th, 2006, 09:00 PM
#6
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|