Create Shortcuts

by Todd G. Nist

Program source is available for download: w-createshortcut.p
This program demonstrates how to create a shortcut in Windows and how to modify it. More specifically, the demo will create a folder called "SomeApplication", place a link to a "Readme.txt" file into the folder created, add it to the end users desktop, and create a link to this website under "Favorites".

By using the SHAddToRecentDocs() call, a shortcut can be created on the fly and added to the user's Documents item on the Start menu. Then by using the SHFileOperation function, one can move and rename files or folders across drives. By applying the SHGetSpecialFolderLocation API, we can get the current user's "Special" systems paths - their Start Menu, their Recent Files path, and others.

The code uses SHAddToRecentDocs to create shortcuts, SHGetSpecialFolderLocation to find the appropriate folders for the system, and SHFileOperation to create a folder, move and then rename the shortcuts. The end result is the ability to create any shortcut you want, to any file you want, and place it anywhere on the user's system. The example code does not do all the necessary error checking so if run more then once, you may encounter errors.

API-procedures used in this example are listed here to be included in the search index:
PROCEDURE SHAddToRecentDocs          EXTERNAL "shell32.dll" :
PROCEDURE SHFileOperationA           EXTERNAL "shell32.dll" :
PROCEDURE SHGetPathFromIDListA       EXTERNAL "shell32.dll" :
PROCEDURE SHGetSpecialFolderLocation EXTERNAL "shell32.dll" :
PROCEDURE SHChangeNotify             EXTERNAL "shell32.dll" :
PROCEDURE CoTaskMemFree              EXTERNAL "ole32.dll" :
PROCEDURE GetTempPathA               EXTERNAL "kernel32.dll" :
PROCEDURE Sleep                      EXTERNAL "kernel32.dll" :
PROCEDURE FindClose                  EXTERNAL "kernel32.dll" :
PROCEDURE FindFirstFileA             EXTERNAL "kernel32.dll" :

Attachments

w-createshortcut.p.zip : example