Creating a Windows shortcut
By: Microsoft Corp. Date: 24/06/2000

Put the following declaration in a module:

Declare Function fCreateShellLink Lib "VB5STKIT.DLL" ( _
ByVal lpstrFolderName As String, ByVal lpstrLinkName As String, _
ByVal lpstrLinkPath As String, _

ByVal lpstrLinkArgs As String) As Long

Then use code like the following to create a shortcut:

x = fCreateShellLink("folder", "link title", "path", "args")

Replace "folder" with the path of the new shortcut. To put it on the Desktop, type "..\..\Desktop". "link title" is just the title of the link, while "path" is the target file for the shortcult. "args" contains the optional command-line arguments (i.e. /p /c) for the program: if there are no arguments, type "".
For example, to create a shortcut to C:\MyFolder\Program.Exe on the Desktop, use the code:

Dim x As Long
x = fCreateShellLink("..\..\Desktop", "My Link", _
"C:\MyFolder\Program.Exe", "")

If you want to put the shortcut in a special folder (i.e. Start Menu, Favorites, Fonts) see Creating a Windows shortcut in a special folder.

Click Here!

Visual Basic Programming Zone is a website by Lorenzo Dalla Vecchia.
To contact the Webmaster, click here.
Hosted by InWind: