【转】快捷方式lnk文件格式详解(英文)

 
转自: http://www.stdlib.com/art6-Shortcut-File-Format-lnk.html

You should consider using the IShellLink interface which is a safe way to handle windows shortcuts. If you have a strong reason not to use that interface then I have to remind you that this file format is not documented by Microsoft. I cannot say that the info gathered here is accurate nor that it will work in the future.

 .LNK File Format 
 1. Header 
 2. Shell Item Id List 
 3. File Location Info 
 4. Description 
 5. Relative Path 
 6. Working Directory 
 7. Command Line Arguments 
 8. Icon Filename 
 9. Additonal Info 

1. Header
SizeContentsDescription
4 bytesAlways 4C 00 00 00This is how windows knows it is a shortcut file
16 bytesGUID for shortcut filesThe current GUID for shortcuts. It may change in the future. 01 14 02 00 00 00 00 00 C0 00 00 00 00 00 46
1 dwordShortcut flagsShortcut flags are explained below
1 dwordTarget file flagsFlags are explained below
1 qwordCreation time 
1 qwordLast access time 
1 qwordModification time 
1 dwordFile lengthThe length of the target file. 0 if the target is not a file. This value is used to find the target when the link is broken.
1 dwordIcon numberIf the file has a custom icon (set by the flags bit 6), then this long integer indicates the index of the icon to use. Otherwise it is zero.
1 dwordShow Windowthe ShowWnd value to pass to the target application when starting it. 1:Normal Window 2:Minimized 3:Maximized
1 dwordHot KeyThe hot key assigned for this shortcut
1 dwordReservedAlways 0
1 dwordReservedAlways 0

Shortcut flags
BitMeaning
0Shell item id list is present
1Target is a file or directory
2Has a description
3Has a relative path
4Has a working directory
5Has command line arguments
6Has a custom icon.

Target flags
BitMeaning
0Target is read only.
1Target is hidden.
2Target is a system file.
3Target is a volume label. (Not possible)
4Target is a directory.
5Target has been modified since last backup. (archive)
6Target is encrypted (NTFS partitions)
7Target is Normal
8Target is temporary.
9Target is a sparse file.
10Target has reparse point data.
11Target is compressed.
12Target is offline.


Last Access and Modified time offsets corrected thanks to JimmyW

Shell Item Id List

Note: This section exists only if the first bit for shortcut flags is set the header section. If that bit is not set then this section does not exists.

The first word contains the size of the list in bytes. Each item (except the last) in the list contains its size in a word fallowed by the content. The size includes and the space used to store it. The last item has the size 0. These items are used to store various informations. For more info read the SHITEMID documentation.


File Location Info

This section is always present, but if bit 1 is not set in the flags value, then the length of this section will be zero. The header of this section is described below.

SizeDescription
1 dwordThis length value includes all the assorted pathnames and other data structures. All offsets are relative to the start of this section.
1 dwordThe offset at which the basic file info structure ends. Should be 1C.
1 dwordFile available on local volume (0) or network share(1)
1 dwordOffset to the local volume table.
1 dwordOffset to the base path on the local volume.
1 dwordOffset to the network volume table.
1 dwordOffset to the final part of the pathname.


Combine the base path string and the final path string to find the filename of the file on the local volume. To find the filename of the file on the network you need to combine the share name in the network volume table with the final path string.

The local volume table

SizeDescription
1 dwordLength of this structure including the volume label string.
1 dwordType of volume (code below)
1 dwordVolume serial number
1 dwordOffset of the volume name (Always 0x10)
ASCIZVolume label

Type of volumes

CodeDescription
0Unknown
1No root directory
2Removable (Floppy, Zip ...)
3Fixed (Hard disk)
4Remote (Network drive)
5CD-ROM
6Ram drive


The network volume table

SizeDescription
1 dwordLength of this structure
1 dwordAlways 02
1 dwordOffset of network share name (Always 0x14)
1 dwordReserved 0
1 dwordAlways 0x20000
ASCIZNetwork share name


 

Description

This section is present if bit 2 is set in the flags value in the header. The first word value indicates the length of the string. Following the length value is a string of ASCII characters. It is a description of the item.


Relative path string

This section is present if bit 3 is set in the flags value in the header. The first word value indicates the length of the string. Following the length value is a string of ASCII characters. It is a relative path to the target.


Working directory

This section is present if bit 4 is set in the flags value in the header. The first word value indicates the length of the string. Following the length value is a string of ASCII characters. It is the working directory as specified in the shortcut properties.


Command line arguments

This section is present if bit 5 is set in the flags value in the header. The first word value indicates the length of the string. Following the length value is a string of ASCII characters. The command line string includes everything except the program name.


Icon filename

This section is present if bit 6 is set in the flags value in the header. The first word value indicates the length of the string. Following the length value is a string of ASCII characters. This the name of the file containing the icon.


Additonal Info Usualy consists of a dword with the value 0.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值