Difference between revisions of "Create a shortcut"
From HashVB
(Expanded article) |
m (Reverted edit of 194.183.227.53, changed back to last version by Dee) |
(One intermediate revision by one user not shown) | |
(No difference)
|
Latest revision as of 13:15, 8 March 2006
Creating shortcuts in VB is relatively easy with help of the Windows Scripting Shell object. This allows you to create a shortcut at a given path and then set all the properties as you need.
Public Sub CreateShortcut(ByVal Path As String, ByVal Name As String, _ ByVal Target As String, Optional ByVal Parameters As String = "") Dim Shell As Object 'WshShell Dim Shortcut As Object 'WshShortcut Set Shell = CreateObject("wscript.shell.1") Set Shortcut = Shell.CreateShortcut(Path & Name & ".lnk") Shortcut.TargetPath = Target Shortcut.Arguments = Parameters Shortcut.Save End Sub
The variables are defined as "Object" because we use late binding, this means you do not need to add a reference and so it is not tied to a specific version of the Windows Scripting Host.
Please note that you can not include command line parameters in the TargetPath property.