Make P&D Wizard create Desktop shortcuts (Article)


Author: W. Baldwin

Version Compatibility: Visual Basic 6, Visual Basic 5

More information:
This article shows that, by adding just 4 lines of code, the Packaging & Deployment Wizard and Setup1.vbp can be easily modified to create Desktop shortcuts, as well as Start Menu shortcuts.

Instructions: Copy the declarations and code below and paste directly into your VB project.

Make P&D Wizard/Setup1.exe create Desktop shortcuts W. Baldwin

These instructions are for VB 6.0, but, with some modification, will probably also work for earlier versions.

The Packaging and Deployment Wizard (P&D Wizard) is a pretty good tool for creating installation packages. Along with the other things it does, it will create shortcuts in the Start Menu. Unfortunately, it won't create Desktop shortcuts; however, with just a few lines of code (added to Setup1.vbp), it can be *easily* modified to create them.

Before attempting this modification, make sure you save the Setup1.vbp files somewhere for backup purposes. Also, read the sections on the MSDN CD, concerning the relationship between the P&D Wizard and Setup1.vbp, and sections concerning how to modify Setup1.vbp. First, check the index tab for 'Setup1.vbp', and read that, which tells you the location of the project files. Then, under the Contents tab, VB, 'Getting Started with VB', 'Find it Fast', read the sections dealing with 'Distributing your applications'.

At the end of this article there are listed some more articles from Microsoft's Knowledge Base, and, which are good supplemental reading.

Although there are a number of ways to create a Desktop shortcut outside of Setup1.exe, modifying Setup1.exe to create them, instead, has a number of benefits, including a built-in install recovery routine in case of failure, and logging the shortcut creation in St6Unst.log. The latter is important, so that, if the user subsequently uninstalls your application, the uninstall routine will also cleanly remove the Desktop shortcut(s).

The procedure is as follows:

1) In frmSetup1's Form_Load event, look for the line:


and modify it to say:


What these lines do, is skip creating a Start Menu Group for the groups 'Start Menu' and 'Programs', because those Groups already exist. We are then adding a *new* keyword "DESKTOP" which tells it to also skip creating a 'DeskTop' group, because we don't want to create that group in the Start Menu, but only add a Desktop shortcut, instead.

2) Then, in basSetup1's 'CreateIcons' Sub, look for the lines:


CreateShellLink strProgramPath, strGroup, strProgramArgs, strProgramIconTitle, fPrivate, sParent

and, insert 3 new lines so that it now looks like:


If UCase(strGroup) = "DESKTOP" Then
strGroup = "..\..\Desktop"
End If

CreateShellLink strProgramPath, strGroup, strProgramArgs, strProgramIconTitle, fPrivate, sParent

Important note: By modifying Setup1.exe this way, Setup1 will now treat the group 'Desktop' as a special keyword and always create the shortcut on the Desktop, rather than as another group in the Start Menu.

3) Now, you're done with Setup1.vbp, and you can compile it. On my system, the .exe is in the PDWizard folder.

Now that you've recompiled Setup1.exe, when you use the P&D Wizard, it should now package the new version of Setup1.exe with your install package.

To make this work, you then need to modify the Setup.lst that was created when you used the P&D Wizard. What you will do is add a new IconGroup, named DeskTop, with one or more icons that you want to be created on the Desktop.

Look for the [IconGroups] section in Setup.lst. It should look something like this, if you have told P&D Wizard to create Start Menu shortcuts:

Group0=Your Application

If the [IconGroups] section doesn't already exist, just add it.

At the bottom of that section, add a new IconGroup for your Desktop shortcut(s) like:


The '1' subscript on the keyword for each line has to be incremented by 1 for each IconGroup you already have, so if Setup.lst already has a Group1, you'd use Group2, PrivateGroup2, Parent2, or Group3, PrivateGroup3, Parent3, etc.

Next, somewhere after the IconGroups section, add a new [DeskTop] section:

Icon1="Your Application.exe"
Title1=Your Application

This is assuming that the target of your Desktop shortcut is in the $(AppPath) folder. $(AppPath) is a macro that tells Setup1.exe that the target program is in your main application folder. There are other macros you can use, instead, that are documented on the MSDN CD and the Knowledge base.

If you want more Desktop shortcuts, just add them under the first one, but use Icon2, Title2, StartIn2, Icon3, Title3, StartIn3, etc.

Now you're done. When you or the user runs Setup1.exe, it should now create a Desktop shortcut.

Check these Microsoft Knowledge Base articles for further information:

Description of Setup.lst Sections (Q189743)
Run Setup1.vbp in the Design Environment (Q189738)
Package and Deployment Wizard Installation Macros (Q189739)
Create Shortcuts (Shell Links) within Windows (Q155303)

Note: The last one, above, covers how to create shortcuts in VB 5.0, using the fCreateShellLink API. That example doesn't work correctly in 6.0, but you can find the updated example which *does* work in 6.0 at At that website, click on 'API List', then search for fCreateShellLink, then click the 'CreateShellLink V6' example.