shortcut TacShortcut component
Hierarchy Properties Methods Example
Return to Introduction  Previous page  Next page
The acShortcut component lets you to quickly and easily create a shortcuts (also known as shell links) to files and folders (in any location) and read the information from shorcut files (.lnk).  

How to read the information from shortcut ?
Just point the FileName property to the .lnk file and read the information from other properties:  
LinkTargetPoints to the file which should be opened on starting s shortcut (on clicking the shortcut icon);  
ParametersThe command-line parameters for executable file specified by LinkTarget property. (if LinkTarget is an EXE);  
WorkingDirectoryWorking directory for executable file specified in LinkTarget property. (if LinkTarget is an EXE);  
RunAsSpecifies how the window should be opened: minimized, maximized or in its normal state;  
IconLocation, IconIndexPoints the location to icon file or another file which contains the icon resources. IconIndex property specifies the resource index, if IconLocation is an EXE or DLL;  
HotKeySpecifies the key combination which executes a shortcut;  
LargeIcon, SmallIconRead-only properties. Contains the 32x32 and 16x16 icons of shortcut link.  
tip The FILENAME property works either at run- or design-time, so you can play with acShortcut component, pointing the .lnk file at design-time. After specifyng the FILENAME, all other properties will be filled with information about the shortcut.  

How to create a shortcut ?
To create a shortcut you must specify the shortcut information to according properties and call SaveToFile(FileName) method, where the FileName is the name of shortcut. Function returs False when it fails.  
For example, you would like to create a shortcut file on desktop, which points to your current executable file + want to specify the icon #4 from shell32.dll file.  
procedure TForm1.Button1Click(Sender: TObject);  
  acShortcut1.LinkTarget := Application.ExeName;  
  // next two lines will set icon #4 from shell32.dll  
  acShortcut1.IconLocation := acSystemInfo1.DirSystem + '\shell32.dll';  
  acShortcut1.IconIndex := 4;  
  // saving to Test.lnk file on desktop  
  acShortcut1.SaveToFile(acSystemInfo1.DirDesktop + '\Test.lnk');  

How to delete shortcut ?
Shortcuts is usual files, with .LNK extension. To remove a shortcuts — just delete them using standard routines, such like DeleteFile…  

See also
acSystemInfo component.