Click to See Complete Forum and Search --> : Add a desktop shortcut with VB6


Bigtimbre
April 24th, 2001, 05:46 PM
Hello!

I'm writing an install program for an older piece of software..I've got everything done, but I don't know how to add a shortcut to the desktop. I appreciate any help!

antonye
April 25th, 2001, 04:08 AM
This is really easy to do using the WinAPI call to create a shortcut. There's a neat little trick involved though in which you reference the Desktop folder instead of a program group.

To start with, you need to use the fCreateShellLink API call which is included in the VB Setup DLL, vb6stkit.dll, so make sure that you include this in your list of DLLs when you create your cabs/zip file for you setup routine.

In a code module (you can't declare APIs on forms) add this line to declare the API:


Declare Function fCreateShellLink Lib "vb6stkit.dll" (ByVal lpstrFolderName As String, ByVal lpstrLinkName As String, ByVal lpstrLinkPath As String, ByVal lpstrLinkArguments As String, ByVal fPrivate As Long, ByVal sParent As String) As Long


You can now call the fCreateShellLink function with the appropriate parameters, which are:

lpstrFolderName is the name of the folder you want to create the shortcut in.

lpstrLinkName is the name of the shortcut you want displayed.

lpstrLinkPath is the full path to the executable you want the shortcut to point to.

lpstrLinkArguments is any additional command-line switches you want the shortcut to pass to the executable.

fPrivate declares whether this is a private or public shortcut, for use when you have user profiles.

sParent is the parent folder where the function starts looking for the folder from.

So, if you wanted to create a shortcut to Notepad.exe (which is in the c:\windows\ directory), and place this on the desktop, we can reference the "desktop" folder using a relative path, starting from the "Programs" group, you would want to add the following code into your program:


Dim bSuccess As Boolean

bSuccess = fCreateShellLink("..\..\Desktop" & vbNullChar, "Notepad", "c:\windows\notepad.exe", "" & vbNullChar, False, "$(Programs)")

MsgBox bSuccess


This should create your shortcut and pop up a box with the result - "True" if it worked and "False" if it didn't.

Hope this helps.

LagMonster
April 25th, 2001, 03:15 PM
I never bothered to look into that but it is cool.

Thanks