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?
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
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.