ShellLinker, ver. 2.0.0

[Static methods] [Types]
[Hints] [Known Bugs] [Comments]

ShellLinker is a unit that allows you to easily create, read, and execute shell links (shortcuts). It can handle links to files, folders, or virtual objects like printers or system folders. You can set/get all properties of a link, like parameters, icon, hotkey, and show state.

ShellLinker does not work with Delphi 1 and 2.

Static Methods

CreateLink function CreateLink(Title, Folder, Target, Parameters, Description: String): Boolean;
Creates a link with the specified title in the specified folder.
Title is the title of the link file.
Folder is the folder in which the link is created.
Target is the file or folder the link is pointing to.
Parameters is the parameters with which to call the target.
Description is a description of the link.
Returns False on error
CreateLinkEx function CreateLinkEx(Title, Folder: String; LinkInfo: TLinkInfo): Boolean;
Creates a link with the specified title in the specified folder, using a TLinkInfo record.
Title is the title of the link file.
Folder is the folder in which the link is created.
LinkInfo contains all relevant data on the link to create. See description of the TLinkInfo type below.
NOTE: All unused fields in LinkInfo should be zeroed out.
Returns False on error
GetLinkInfo function GetLinkInfo(FileName: String; var LinkInfo: TLinkInfo): Boolean;
Gets information about a link. The informations is returned in LinkInfo.
Returns False on error
ExecuteLink function ExecuteLink(FileName: String; Handle: HWND; Verb: PChar; [ForceRestore: Boolean = False]);
Executes (runs) a link.
FileName is the full path of the link file.
Handle is the window that will receive any message boxes (usually set to 0 or the application's handle).
Verb can be one of the values used in the ShellExecute method (nil, 'open', 'explore', or 'print'). Use nil if you just want to open the link.
ForceRestore is optional (default False). If set to true, ExecuteLink will open the link in normal state, regardless of whether the link has been set to start minimized or maximized.
NOTE: Remember to include the extension '.lnk' in the file name.
NOTE: The link will be executed using the parameters and start folder contained in the link.
NOTE: You can use GetLastError to get error info if the method returns False.
Returns False on error
GetTargetDisplayName function GetTargetDisplayName(ClsID: PItemIDList): String;
Gets the display name of the target specified by ClsID. This method is useful for links to virtual objects. For links to files and folders the display name is identical to the target path.
Returns empty string on error
GetTargetIconHandle function GetTargetIconHandle(ClsID: PItemIDList; SmallIcon, LinkOverlay: Boolean): Cardinal;
Gets the handle to the icon of the target specified by ClsID.
Returns 0 on error
GetSpecialFolderPath function GetSpecialFolderPath(FolderIndex: Integer): String;
Gets the path of a system folder. This is useful when you need to create a link on the desktop or in other special folders. CSIDL_DESKTOPDIRECTORY, CSIDL_STARTMENU, and CSIDL_STARTUP are probably the most relevant parameters.
Returns empty string on error
LinkHotKeyToWord function LinkHotKeyToWord(Modifiers, Key: Word): Word;
Creates a hotkey value from the specified modifiers and virtual key code. Useful when using CreateLinkEx to create a link with a hotkey.
NOTE: Valid modifiers are HOTKEYF_CONTROL, HOTKEYF_SHIFT, and HOTKEYF_ALT (found in the CommCtrl unit).

WordToLinkHotKey function WordToLinkHotKey(HotKey: Word): TLinkHotKey;
Splits a hotkey value into modifiers and virtual key code, and returns the result in a LinkHotKey record. Useful when you have obtained a hotkey by using GetLinkInfo.

TranslateHotKeyToText function TranslateHotKeyToText(HotKey: Word): String;
Translates a hotkey value into text (eg. 'Ctrl+Alt+X').

Types

TLinkInfo
TLinkInfo = record
  Target: String;          // Path to link target file   - empty for virtual folders
  ClsID: PItemIDList;      // Absolute CLSID (PIDL) of target
  WorkDir: String;         // Working directory          - empty for virtual folders
  Parameters: String;      // Parameters sent to path    - empty for virtual folders
  Description: String;     // Description of link
  IconPath: String;        // File containing icon       - often same as Target
  IconIndex: Integer;      // Index of icon in the icon file
  HotKey: Word;            // HotKey (like Alt+Shift+F)  - numeric
  ShowState: TShowState;   // Normal, minimized, or maximized
end;
Contains data on a shell link. Used with CreateLinkEx and GetLinkInfo.
TLinkHotKey
TLinkHotKey = record
  Modifiers: Word;
  Key: Word;
end;
Contains a hotkey split into modifiers (ctrl, alt, shift, or win) and a virtual key code. Used with WordToLinkHotKey.

Hints

Known Bugs

Comments

ShellLinker is freeware. Feel free to use and improve it, but please include all original files if you redistribute the zip-file. If you have any comments or corrections I would very much like to hear them.

Get the latest version from http://www3.brinkster.com/troels/delphi.asp.

Troels Jakobsen
delphiuser@get2net.dk