Add a desktop shortcut with VB6
Results 1 to 3 of 3

Thread: Add a desktop shortcut with VB6

  1. #1
    Registered User Bigtimbre's Avatar
    Join Date
    Apr 2001
    Location
    Anchorage, AK
    Posts
    134

    Post Add a desktop shortcut with VB6

    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!

  2. #2
    Registered User
    Join Date
    Jan 1999
    Location
    London, Great Britain
    Posts
    300

    Thumbs up

    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:

    Code:
    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:

    Code:
    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.
    I'd rather die peacefully in my sleep like my Grandfather,
    than screaming in terror like his passengers.
    Jim Harkins
    <a href="http://www.Horrible.Demon.co.uk/" target="_blank">http://www.Horrible.Demon.co.uk/</a>

  3. #3
    Registered User
    Join Date
    Dec 2000
    Location
    Circle Pines,MN,USA
    Posts
    805

    Post

    I never bothered to look into that but it is cool.

    Thanks

Bookmarks

Posting Permissions

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