Creating Shortcuts with VB
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 5 of 5

Thread: Creating Shortcuts with VB

  1. #1
    Join Date
    Jan 2003

    Creating Shortcuts with VB

    I currently have an app that runs under win9X, one of the features is to create shortcuts on the desktop, I know need the program on winXP but the API call I use no longer works!

    Private Declare Function OSfCreateShellLink Lib "vb6stkit.dll" Alias "fCreateShellLink" _
    (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

    Do you know why this is? is there a different line of code, the machine I am testing it on has all the right DLLs but it just wont work

    Thanks for any help

  2. #2
    Join Date
    May 2002
    Colombo,Sri Lanka

  3. #3
    Join Date
    Jan 2003
    Thanks for the site but that is the code i already have, it doesnt work on XP, i think it is to do with the first arguement, in all the info sources i have found it has had "..\..\desktop" but the desktop path in xp is different! any more help would be greatly appreciated!



  4. #4
    Join Date
    Sep 2001
    Québec, Canada
    There is another way to create a shortcut. To make the following code works, add a reference to Windows Script Host Model:

        'code modified from 
        Dim WshShell As New WshShell
        Dim oShellLink As WshShortcut
        'Create and save the shortcut
        'Here, it is important the the extension end by .lnk
        Set oShellLink = WshShell.CreateShortcut( "C:\TestLink.lnk" )
        With oShellLink
    	'Shortcut to which file (can be anything, .exe, .doc, ...)
            .TargetPath = "C:\WINNT\SYSTEM32\calc.exe"
            .WindowStyle = 1
            .IconLocation = "C:\WINNT\SYSTEM32\calc.exe, 0"
            .Arguments = ""
        End With
        Set WshShell = Nothing
        Set oShellLink = Nothing
    Note that you'll have to use GetSpecialFolders to know where is the ShortCut and change "C:\TestLink.lnk" by the desktop folder AND the name of the link

    CodeGuru VB FAQ Visual Basic Frequently Asked Questions
    VB Code color Tool to color your VB code on CodeGuru
    Before you post Importants informations to know before posting

  5. #5
    Join Date
    Jan 2003
    That worked a treat thanx

Posting Permissions

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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

This is a survey!

HTML5 Development Center