Share via


Creating External Shortcuts with Parameters

David Meego - Click for blog homepageI was asked recently if it was possible to create a Shortcut from Microsoft Dynamics GP to launch an external application and pass parameters to the application. 

The usual method of achieving this with a Windows Shortcut is to add a space and then add the parameters to the Target field.  If you try the same approach with a Dynamics GP shortcut by adding the parameters to the Command Line field, you will receive a "The File doesn't exist in the specified location" error message (shown below).

Shortcut Error

This is because Dynamics attempts to validate the command line to make sure the application exists before it is launched and this validation does not handle parameters. 

Note: You can also get this error if the file you are attempting to launch really does not exist. While writing this article I found a couple of support cases where this error was occurring on login because an external shortcut in the Startup folder was pointing to a non-existent file.


The resolution to this issue is to use a batch or command file with the full command line you need including the application path and the parameters and then pointing the Dynamics GP shortcut to this batch or command file.

The batch or command file is just a text file with the extension of the file changed to BAT or CMD.  The contents of the batch or command file can just be the path to the application followed by the parameters. 

For example: 

Notepad.exe "C:\My Documents\Test.txt"

Note: If any of the paths passed contain spaces you must wrap the path with double quotes (").

If execute this shortcut you will notice that a DOS window will be left open until you close the application launched. To resolve this issue and "spawn" the application as a separate process we can use the Start command. The DOS window will open and then close immediately. So the command line becomes:

Start Notepad.exe "C:\My Documents\Test.txt"

This will work if the application path does not contain any spaces.  If the path contains spaces and you use double quotes (") to wrap the application path, the Start command will interpret this as a window title and so ignore the application path and attempt the execute the next parameter. To prevent this from occurring we can add a window title to the syntax.

We can also use the @ command to prevent the Start command showing in the DOS window. So the final command line becomes:

@Start "Shortcut" Notepad.exe "C:\My Documents\Test.txt"

or more generically:

@Start "<Window Title>" "<Application Path>" <Parameter1> [<Parameter2>] ....

Hope you find this useful.

David

Comments

  • Anonymous
    August 25, 2009
    Posting from DynamicAccounting.net http://msdynamicsgp.blogspot.com/2009/08/creating-external-shortcuts-with.html

  • Anonymous
    February 11, 2010
    Hi David, Just wondering if there is a way to edit the shortcuts you created in GP 10.0? When I moved a few files to different path in the network, shortcuts I created in GP became in valid. I could not figure out how to correct them. Any help is appreciated.

  • Anonymous
    February 11, 2010
    Hi Sajith You should just be able to right click on them and select properties, then edit the path. Otherwise, just create them again. David

  • Anonymous
    January 10, 2017
    How exactly do you add a shortcut to GP?

  • Anonymous
    January 17, 2017
    Hi PaulOnce logged into Dynamics GP, on the Home page, in the left hand pane, right click on Shortcuts and select Add.David