PDA

View Full Version : Solved: Returning the Path of a Shortcut as a String



rrenis
02-12-2008, 04:15 AM
Hi - I found this peice of code that works great when returning the path of a shortcut that is located in a 'SpecialFolder' such as the desktop. The problem is that I need it to point at a non 'SpecialFolder' i.e. C:\Temp and return the path of a selected shortcut in that directory. I'm having trouble altering this code to work when the shortcut "My Project" is located in C:\Temp instead of the Desktop. :think:

Public Sub Tester()
Dim WSHShell As Object
Dim MyShortcut As Object
Dim sDesktoPath As String
Dim sShortcutName As String
sShortcutName = "My Project"
Set WSHShell = CreateObject("WScript.Shell")
sDesktopPath = WSHShell.SpecialFolders("Desktop")
Set MyShortcut = WSHShell.CreateShortcut(sDesktopPath & "\" & sShortcutName & ".lnk")
MsgBox MyShortcut.TargetPath
Set WSHShell = Nothing
Set MyShortcut = Nothing
End Sub

Any help would be greatly appreciated!

cheers,
rrenis

stanl
02-12-2008, 04:40 AM
One way might be to use WMI... here is a reference

http://www.microsoft.com/technet/scriptcenter/resources/qanda/dec04/hey1208.mspx

Stan

rrenis
02-12-2008, 06:31 AM
Thanks Stan - I've had a look at that but so far can't get it to work. Thanks for the suggestion though.
:beerchug:
Cheers,
rrenis

rrenis
02-12-2008, 07:27 AM
Hi all - found a solution using oShell.NameSpace, oShellLink = oFolderItem.GetLink and oShellLink.Path to get the path of a particular shortcut just incase anyone else is interested.

Cheers,
rrenis