Get the stored path from a shortcut!
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
    Location
    IL, USA
    Posts
    1,090

    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()
    Code:
    ‘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
          Err.Clear
          GoTo exit_sub
       else
          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
          else
             MsgBox ShortcutName & " is not a shortcut!", vbInformation
          End If
       End If
    exit_sub:
       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 08:13 AM.

  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Nice!

    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

This is a CodeGuru survey question.


Featured


HTML5 Development Center