VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Get Shortcut's Target

by Michael L. Canejo (28 Submissions)
Category: Files/File Controls/Input/Output
Compatability: Visual Basic 5.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (11 Votes)

After looking all over on VBC 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.

Rate Get Shortcut's Target


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
  
Error_Loading:
  GetTarget = "Error occured."
End Function

Download this snippet    Add to My Saved Code

Get Shortcut's Target Comments

No comments have been posted about Get Shortcut's Target. Why not be the first to post a comment about Get Shortcut's Target.

Post your comment

Subject:
Message:
0/1000 characters