Otman Beggas Otman Beggas - 2 months ago 20
Vb.net Question

How to get Full Target String from Shortcut lnk

Please i am trying to get the full target from a shortcut file. I am using the below function

Public Function GetLnkTarget(lnkPath As String) As String
Dim Obj As Object
Obj = CreateObject("WScript.Shell")
Dim Shortcut As Object
Shortcut = Obj.CreateShortcut(lnkPath)
Return Shortcut.TargetPath.ToString
End Function


For example i have a shortcut .lnk file with the following target:

C:\WINDOWS\system32\wscript.exe /e:VBScript.Encode Folder/skype.exe


When i use the function to get the target from the following .lnk
D:\Shortcut.lnk

GetLnkTarget("D:\Shortcut.lnk")


i get the following output

C:\WINDOWS\system32\wscript.exe


So it does not return the full string of the Target as "/e:VBScript.Encode Folder/skype.exe" is missing from the output.

Answer

You need to access the Shortcut.Arguments property. See here for the reference of the shortcut object.

https://msdn.microsoft.com/en-us/library/f5y78918(v=vs.84).aspx

So your code will be:

Return Shortcut.TargetPath.ToString & " " & Shortcut.Arguments
Comments