Deployment Tip: Creating Shortcuts


Photo by NatalieMaynor

One question that we’ve had a few times is how to create shortcuts to applications when deploying with PDQ Deploy. Typically this is either because the application’s installer didn’t create a shortcut or there is a need to create custom shortcuts with special parameters. We have, as a planned enhancement, the ability to create shortcuts directly within the application. But until then you can use the VBScript functionality in PDQ Deploy to run a short VBScript file that will do the heavy lifting.

Here’s a simple example, it creates a shortcut on all user’s desktops to the venerable Notepad application:

set shell = WScript.CreateObject("WScript.Shell" ) 
desktop = shell.SpecialFolders("AllUsersDesktop" )
set link = shell.CreateShortcut(desktop & "\My Notepad.lnk" )
link.TargetPath = "%SystemRoot%\notepad.exe"
link.WindowStyle = 1
link.IconLocation = "%SystemRoot%\notepad.exe"
link.Description = "Start Notepad"
link.WorkingDirectory = "%SystemRoot%"
link.Save

Save this to a file name “notepad.vbs” and then select it as the installer file in PDQ Deploy and you’re good to go.  In PDQ Deploy Pro you can create it as a second package within an installer to have it follow right after another installation. 

It’s pretty straight forward how it works but there are a couple of things you’ll need to know to customize it for your needs.

SpecialFolders

In order to make it easier to avoid hard coding paths to files you can use the SpecialFolders object which gives access to the actual paths of a number of the built-in folders. Some of these folders are available as environment variables but not all.  The available folders are:

AllUsersDesktop
AllUsersStartMenu
AllUsersPrograms
AllUsersStartup
Desktop
Favorites
Fonts
MyDocuments
NetHood
PrintHood
Programs
Recent
SendTo
StartMenu
Startup
Templates

WindowStyle

This property has 3 possible values:

1 = Normal window
3 = Maximized window
7 = Minimized window

Arguments

To pass parameters to the application don’t add them to the TargetPath property, instead use the Arguments property. For example, to use notepad to open a file called “Hello World.txt” add this line:

link.Arguments = "Hello World.txt"

HotKey

A hot key can be added to a shortcut to allow quick keyboard access. Use “Ctrl+”, “Alt+”, or “Shift+” and a key. For example:

link.HotKey = "Ctrl+Alt+N"

That should be enough to get you going creating shortcuts. As always, please feel free to post any comments or questions here or in our forums and we’ll do our best to help you get it working.