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

Thread: Creating Shortcuts with VB

  1. #1
    Join Date
    Jan 2003
    Posts
    17

    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
    Location
    Colombo,Sri Lanka
    Posts
    1,110

  3. #3
    Join Date
    Jan 2003
    Posts
    17
    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!

    Thanks

    Si

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

    Code:
        'code modified from 
        'http://www.vbforums.com/showthread.php?threadid=225479&highlight=shortcut+create 
        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 = ""
            .Save
        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

    JeffB
    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
    Posts
    17
    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center