ProAnswers.org

How to retrieve the target path of any existing shortcut such as a lnk file in Visual Basic?

How do you retrieve the target path of any existing shortcut such as a lnk file in Visual Basic?

Here is how to open a Windows Shortcut file Using VB6. This is a safe and documented method.

Create a New VB6 Project

In the Project References Add “Windows Script Host Object Model”

Place a Command Button on the form named CommandButton1

Click on CommandButton1

Private Sub CommandButton1_Click()

Dim Oshell As New WshShell

Dim Osh As WshShortcut

Dim Fn As String

Dim Otarget As String

'Set the path and file name of the shortcut

Fn = “C:\shortcut path\shortcut filename.lnk”

’ If the shortcut file is existing, it will open the existing file

Set Osh = Oshell.CreateShortcut(Fn)

Otarget = Osh.TargetPath

’ Using the Watch window see the other properties of Osh object

End Sub