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.