UtterAccess HomeUtterAccess Wiki

Welcome Guest ( Log In | Register )

Custom Search
Edit Discussion
> GetLinkTarget    

Retreives the target of a .lnk file, optionally including any arguments. If the passed string is not a link, the string which was passed is returned.

This does not use the more common scripting method and therefore isn't prone to stops from antivirus, etc.

This does not work in the following scenarios:
- Resolving a link to a specialized location (Computer, Game Shortcuts (in Vista/Win7), etc). In this case, the Path property is a zero length string, and the return of the function as well is a ZLS
- Resolving a link to a file which has security restrictions. In this case, the object is not created, an error is thrown, and the function returns the actual .lnk file itself
- Some programs seem to have oddities in the shortcut creation. For example, a shortcut of any of the Office applications when dragged from the start menu and placed on the desktop yield a result along the lines of "C:\Windows\Installer\{classID}\appicon.exe" rather than the actual executable to the Office application.

This is unfortunate behavior, and if you have any information on workarounds to either of the issues outlined above, the sharing of that information would be greatly appreciated by the community.



' GetLinkTarget
' http://www.utteraccess.com/wiki/index.php/GetLinkTarget
' Code courtesy of UtterAccess Wiki
' Licensed under Creative Commons License
' http://creativecommons.org/licenses/by-sa/3.0/
' You are free to use this code in any application,
' provided this notice is left unchanged.
' rev  date                          brief descripton
' 1.0  2011-09-29                    
Public Function GetLinkTarget(sLink As String, Optional bIncludeArguments As Boolean = True) As String
 On Error GoTo err_proc
 Dim Ret As String

 With CreateObject("Shell.Application").Namespace(0).ParseName(sLink).GetLink
   Ret = .Path
   If bIncludeArguments Then Ret = Trim(Ret & " " & .Arguments)
 End With

 GetLinkTarget = Ret
 Exit Function
 If Err.Number = 91 Then Ret = sLink
 Resume exit_proc
End Function

Creative Commons License
GetLinkTarget by UtterAccess Wiki is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Editing and revision of the content is freely encouraged; for details, see Expected Usage.

Edit Discussion
Custom Search
Thank you for your support!
This page has been accessed 3,533 times.  This page was last modified 01:35, 30 September 2011 by Jack Leach.   Disclaimers