Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting the "start in" property of a lnk file using VB - Impossible? 1

Status
Not open for further replies.

bjwade62

Programmer
Oct 31, 2002
15
US
Can anyone tell me how to retrieve the "start in" value of an lnk (shortcut) file? I've posted this on different VB sites but no one seems to be able to give me an answer. Must be impossible or very difficult?

Thanks for you time,
Bernie
 
No, it's really easy. Simply add a refernce to the Windows Script Host Object Model library. The code such as the following will do the trick:
[tt]
Option Explicit

Private Sub Command1_Click()
DerefShortCut "c:\shortcut to test.xml.lnk"
End Sub


Public Sub DerefShortCut(strPathToShortcut As String)
Dim wShell As WshShell
Dim wShortcut As WshShortcut

Set wShell = New WshShell

On Error GoTo NotAShortCut
Set wShortcut = wShell.CreateShortcut(strPathToShortcut) '("c:\shortcut to test.xml.lnk")
Debug.Print wShortcut.TargetPath
Debug.Print wShortcut.WorkingDirectory

Exit Sub

NotAShortCut:
If Err.Number = &H80020009 Then
MsgBox "Not a shortcut file"
Else
Err.Raise Err.Number
End If
End Sub

 
Excellent! I can't tell you how many places I posted this question. None of the answers worked ecxept yours. Thanks tons strongm!

and thanks again,
Bernie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top