Saturday, March 7, 2009

The Windows Shortcut File Format

Basic File Structure

The file is structured like this:

File header
Shell item ID list
Item 1
Item 2
etc..
File locator info
Local path
Network path
Description string
Relative path string
Working directory string
Command line string
Icon filename string
Extra stuff

The File Header

This is of course at the start of the file.

The first 4 bytes of the file form a long integer that is always set to 4Ch this it theASCII value for the uppercase letter L. This is used to identify a valid shell link file.

The next 16 bytes is the globally unique identifier GUID of the shell links which is:{00021401-0000-0000-00C0-000000000046} in standard GUID notation or {01h,14h, 02h, 00h, 00h, 00h, 00h, 00h, C0h, 00h, 00h, 00h, 00h, 00h, 46h} as it iscomposed of bytes in the file. It appears that in the future, Microsoft may redefinethe file format and this will be used to indicate which version to use.The next item is a long integer which consists of a number of flags. This isimportant, because it indicates which of the optional parts of the file are present.

The next item is a long integer that contains file attributes of the target file. If thetarget is not a file (see flags bit 1), then this is set to zero. The resolver uses thesewhen the link is broken to match the link with the correct target.

The next three items are 64 bit integers that specifiy the various time information for the file.
Creation time
Modification time
Last access time
The next item is a long integer which contains the length of the target file.
If the file has a custom icon (see flags bit 6), then this long integer indicates theindex of the icon to use. Otherwise it is zero.
The next long integer specifies the ShowWnd value to pass to the target application when starting it. For your convenience, the values are reproduced below. It isunlikely, that most of these values are valid. Only values 1, 2 and 3 are permitted inthe shortcut property page.
SW_HIDE 0 Cool...
SW_NORMAL 1
SW_SHOWMINIMIZED 2
SW_SHOWMAXIMIZED 3
SW_SHOWNOACTIVATE 4
SW_SHOW 5
SW_MINIMIZE 6
SW_SHOWMINNOACTIVE 7
SW_SHOWNA 8
SW_RESTORE 9
SW_SHOWDEFAULT 10
The next long integer specifies the hotkey assigned to the shortcut.
The last two long integers are always zero. They are probably reserved for future use.
The Shell Item Id List.
This item is only present if bit 0 is set in the flags word of the header.
An entire book could be written on the contents of this item. Essentially it indicateshow to get from the desktop to the specified item. The actual contents are highlyvariable. The following are the only constant items about the list.
The first unsigned short integer indicates the total length of the list so it can beskipped easily.
Inside the list, each item begins with an unsigned short integer that indicates thelength of the item. The length includes the size of the length value.
The last item is length 0.
Lookup ITEMIDLIST in most any Win32 documentation for more info on this item.

No comments:

Post a Comment