Search Tools Links Login

Get Shortcut's Target

Posted: 2003-06-01
By: ArchiveBot
Viewed: 73

Filed Under:

VB6 Code Cache

No attachments for this post

After looking all over on PSC i was unable to find Short, Simple and Clean code to get the target path of a window's shortcut (.lnk) file, so here is an easier way.

Original Author: Michael L. Canejo


Public Function GetTarget(strPath As String) As String
  'Gets target path from a shortcut file
On Error GoTo Error_Loading
  Dim wshShell As Object
  Dim wshLink As Object
  Set wshShell = CreateObject("WScript.Shell")
  Set wshLink = wshShell.CreateShortcut(strPath)
  GetTarget = wshLink.TargetPath
  Set wshLink = Nothing
  Set wshShell = Nothing
  Exit Function
  GetTarget = "Error occured."
End Function

Comments on this post

No comments have been added for this post.

You must be logged in to make a comment.