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

Thread: Get the stored path from a shortcut!

  1. #1
    Join Date
    Sep 2001
    IL, USA

    Get the stored path from a shortcut!

    It seems when there is a question about How to get the stored path in a shortcut the answer on this forum was to use a code that loops through all items in a folder and display the info about all shortcuts in that folder. In the code below you can specify the folder and the shortcut and you'll get the info for that shortcut only. I thought it's a good idea to answer this frequently asked question directly.private Sub Command1_Click()
    ‘Add reference to Microsoft Shell Controls and Automation and add a button to a form.
       Dim shl as Shell, file as FolderItem, fld as Folder
       Dim lnk as ShellLinkObject, i as Long, folderPath as string
       set shl = new Shell
       'you can use an input box to get the folder path
       folderPath = "c:\windows\Desktop\"
       set fld = shl.NameSpace(folderPath)
       'to use browser remove the comment from the next line
    ' set fld = shl.BrowseForFolder(me.hWnd, "Select Folder that has shortcut file", 0, ssfDESKTOP)
       ShortcutName = InputBox("Enter shortcut name with extention .lnk", "Shortcut name")
       If Not Right(ShortcutName, 4) = ".lnk" then
         ShortcutName = ShortcutName & ".lnk"
       End If
       on error resume next
       set file = fld.Items.Item(ShortcutName)
       If Err <> 0 then
          MsgBox ShortcutName & " is inaccessable!", vbCritical
          GoTo exit_sub
          If file.IsLink then
              set lnk = file.GetLink
              MsgBox "Name: " & file.Name & vbCrLf & _
              "Description: " & lnk.Description & vbCrLf & _
              "Path: " & lnk.Path & vbCrLf & _
              "WorkingDirectory: " & lnk.WorkingDirectory & vbCrLf, vbInformation
             MsgBox ShortcutName & " is not a shortcut!", vbInformation
          End If
       End If
       set lnk = nothing
       set file = nothing
       set fld = nothing
       set shl = nothing
    End Sub

    Help us improve our answers by rating them.
    Last edited by Cimperiali; August 25th, 2003 at 07:13 AM.

  2. #2
    Join Date
    Jul 2000
    Milano, Italy


    Only a pity I am already out of votes...
    Have a nice day, you BrainStormingGuru

    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Michael
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010

    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

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

On-Demand Webinars (sponsored)