问题
Several frameworks and languages seem to have lnk file parsers (C#, Java, Python, certainly countless others), to get to their targets, properties, etc. I'd like to know what is the general approach to reading lnk files, if I want to parse the lnk in another language that does not have said feature. Is there a Windows API for this?
回答1:
There is not an official document from Microsoft describing lnk file format but there are some documents which have description of the format. Here is one of them: Shortcut File Format (.lnk)
As for the API you can use IShellLink Interface
回答2:
This is an old post, but here is my C# implementation for lnk processing that handles the entire spec
https://github.com/EricZimmerman/Lnk
more info and command line tool here
http://binaryforay.blogspot.com/2016/02/introducing-lecmd.html
回答3:
Simply use lnk file parser at J.A.F.A.T. Archive of Forensics Analysis Tools project.
See lnk-parse-1.0.pl at http://jafat.sourceforge.net
There seems no have no dependencies. Syntax is simple and link file becomes a simple text in standard output and to be usable on Linux.
回答4:
@Giorgi: Actually, there is an official specification of lnk files, at least it is claimed so: http://msdn.microsoft.com/en-us/library/dd871305%28PROT.10%29.aspx However, for some reason, the link seems to be dead, and after downloading the whole (45Megs) doc package (Application_Services_and_NET_Framework.zip), it appears that it does not include the file MS-SHLLINK.pdf.
But is this really surprising ?
Once you got the file format, shouldn't be too hard to write code to read it.
回答5:
Using WSH-related components seems the most convenient option to read .lnk
files in most languages on a post-XP windows system. You just need access to the COM environment and instantiate the WScript.Shell
Component. (remember that on win, references to the Shell usually refer to explorer.exe
)
The following snippet, e.g. does the thing on PHP: (PHP 5, using the COM object)
<?php
$wsh=new COM('WScript.Shell'); // the wsh object
// please note $wsh->CreateShortcut method actually
// DOES THE READING, if the file already exists.
$lnk=$wsh->CreateShortcut('./Shortcut.lnk');
echo $lnk->TargetPath,"\n";
This other one, instead, does the same on VBScript:
set sh = WScript.CreateObject("WScript.Shell")
set lnk = sh.CreateShortcut("./Shortcut.lnk")
MsgBox lnk.TargetPath
Most examples in the field are written in VB/VBS, but they translate well on the whole range of languages supporting COM and WSH interaction in a form or another.
This simple tutorial may come handy, as it lists and exemplifies some of the most interesting properties of a .lnk
file other than the most important: TargetPath
. Those are:
WindowStyle
,Hotkey
,IconLocation
,Description
,WorkingDirectory
来源:https://stackoverflow.com/questions/3425969/general-approach-to-reading-lnk-files