As a yard, the work will often use a variety of tools, in order to improve the efficiency of the brick, I have been using executor as a quick start tool, want to open what program directly snapped a few keyboards, forcing lattice full, and then get to a new skill: A folder to store the shortcuts of common programs, Then add the path of this folder to the path system environment variable, you can use "Win + R" To open the common program. Disadvantage is inconvenient management, many programs have been deleted, but the shortcut is still in, causing a lot of invalid shortcuts, so you want to write a program to automatically delete invalid shortcuts, but did not find a ready to parse the shortcut file of the library, it seems to be able to build their own wheels.
Detailed documentation for this file format is available on MSDN. A lot of information in the file, but most of them do not use, do not want to spend time to toss, only resolved three: the target path, whether it is a directory and shortcut keys.
This is basically the class, relatively simple, not a few lines of code:
1 Public classWinshortcut2 {3 Public stringTargetPath {Get;Private Set; }4 Public BOOLisdirectory {Get;Private Set; }5 6 string_hotkey;7 Public stringHotKey {Get{returnString.isnullorwhitespace (_hotkey)?"No": _hotkey; }Private Set{_hotkey =value;} }8 9 PublicWinshortcut (stringpath)Ten { One Parse (path); A } - - Public Override stringToString () the { - return string. Format ("destination path: \ "{0}\", whether it is a folder: {1}, shortcut: \ "{2}\"", TargetPath, Isdirectory, HotKey); - } - + voidParse (String shortcutpath) - { + using(varFS =NewFileStream (Shortcutpath, FileMode.Open, FileAccess.Read)) A { atFs. Seek ( -, seekorigin.begin); - vardata =New byte[4]; -Fs. Read (data,0, data. Length); - varLinkflags = Bitconverter.toint32 (data,0); - -Fs. Read (data,0, data. Length); in varFileattrflags = Bitconverter.toint32 (data,0); -Isdirectory = (Fileattrflags & WinConsts.FileAttributes.Directory) = =WinConsts.FileAttributes.Directory; to +Fs. Seek ( $, seekorigin.current); -Fs. Read (data,2,2); the varHotKey =Newlist<string> (4); * varHotkeylowbyte = (ushort) data[2]; $ varHotkeyhighbyte = (ushort) data[3];Panax Notoginseng if((Hotkeyhighbyte & (ushort) = = (WinConsts.VirtualKeys.HOTKEYF_CONTROL) = = (ushort) WinConsts.VirtualKeys.HOTKEYF_CONTROL) -Hotkey.add ("Ctrl"); the if((Hotkeyhighbyte & (ushort) = = (WinConsts.VirtualKeys.HOTKEYF_SHIFT) = = (ushort) WinConsts.VirtualKeys.HOTKEYF_SHIFT) +Hotkey.add ("Shift"); A if((Hotkeyhighbyte & (ushort) = = (WinConsts.VirtualKeys.HOTKEYF_ALT) = = (ushort) WinConsts.VirtualKeys.HOTKEYF_ALT) theHotkey.add ("alt"); + if(Enum.isdefined (typeof(Winconsts.virtualkeys), hotkeylowbyte)) - { $ Hotkey.add (((Winconsts.virtualkeys) hotkeylowbyte). ToString ()); $ } -HotKey = String.Join (" + ", HotKey); - theFs. Seek (0x4c, seekorigin.begin); - if((Linkflags & WinConsts.LinkFlags.HasLinkTargetIdList) = =WinConsts.LinkFlags.HasLinkTargetIdList)Wuyi { the varBuffer =New byte[2]; -Fs. Read (Buffer,0, buffer. Length); Wu varSize = bitconverter.toint16 (buffer,0); - FS. Seek (size, seekorigin.current); About } $ if((Linkflags & WinConsts.LinkFlags.HasLinkInfo) = =WinConsts.LinkFlags.HasLinkInfo) - { - varStart = fs. Position;//note the starting position of the LinkInfo -Fs. Seek (8, seekorigin.current); A varBuffer =New byte[4]; +Fs. Read (Buffer,0, buffer. Length); the varLnkinfoflags = bitconverter.toint32 (buffer,0); - if((Lnkinfoflags & WinConsts.LinkInfoFlags.VolumeIDAndLocalBasePath) = =WinConsts.LinkInfoFlags.VolumeIDAndLocalBasePath) $ { theFs. Seek (4, seekorigin.current); theFs. Read (Buffer,0, buffer. Length); the varLocalbasepathoffset = bitconverter.toint32 (buffer,0); the varBasepathoffset = start +Localbasepathoffset; - varLength =0; in FS. Seek (Basepathoffset, seekorigin.begin); the while(FS. ReadByte () >0) the { About++length; the } the varBasepathraw =New byte[length]; the FS. Seek (Basepathoffset, seekorigin.begin); +Fs. Read (Basepathraw,0, basepathraw.length); -TargetPath =Encoding.Default.GetString (basepathraw); the }Bayi } the } the } -}
Click to download the full project
Parsing Windows shortcut files