Extract Target path from a shortcut

W

WhytheQ

I know how to add a target path to a created shortcut:

Dim WSHShell As Object
Dim MyShortcut As Object

Set WSHShell = CreateObject("WScript.Shell")
Set MyShortcut = WSHShell.CreateShortcut(pathwayhere & ".lnk")

With MyShortcut
.targetpath = targetpathwayhere
.Save
End With

.........but if I already have a created shortcut then how do I extract
the target pathway from it, as a string??

any help greatly appreciated

Jason.
 
N

Norman Jones

Hi Jason,

Try something like:

'=============>>
Public Sub Tester()
Dim WSHShell As Object
Dim MyShortcut As Object
Dim sDesktoPath As String
Const sShortcutName As String = "YourShortcutName"

Set WSHShell = CreateObject("WScript.Shell")

sDesktopPath = WSHShell.SpecialFolders("Desktop")

Set MyShortcut = WSHShell.CreateShortcut(sDesktopPath _
& "\" & sShortcutName & ".lnk")

MsgBox MyShortcut.TargetPath

End Sub
'<<=============
 
W

WhytheQ

Very nice Norman!
It was using the "CreateShortcut" method that fooled me: I had it in my
head that this would create a new shortcut rather than get a hook on an
existing one !!

all seems to work ok
thanks again
Jason
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top