Results 1 to 6 of 6

Thread: Question on shortcuts parameters

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2005
    Posts
    181

    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

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2005
    Posts
    181

    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

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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:
    1. Dim args() As String = Environment.GetCommandLineArgs()
    2. For Each arg As String In args
    3.     MessageBox.Show(arg)
    4. 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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    May 2005
    Posts
    181

    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?

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    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:
    1. If Array.IndexOf(Environment.GetCommandLineArgs(), "-safe") <> -1 Then
    2.     'Startup in safe mode.
    3. 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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width