Shortcuts
The Shell
object provides the ability to create shortcuts via the
CreateShortCut
method. This method returns a
WshShortCut
object:
objShortCut = objShell.CreateShortcut(strPath)Once you have created a
Shortcut
object, you can set properties for it.
This object provides the same settings that are available when
creating shortcuts using Explorer.
Table 9-10 lists the properties that can be set for the shortcut.
Table 9-10. Shortcut object properties
|
Parameter |
Type |
Description |
|---|---|---|
|
|
String |
Shortcut description. |
|
|
String |
Hotkey used to execute shortcut. The easiest way to get a hotkey is to use Windows Explorer to create a shortcut and copy the hotkey settings used by the shortcut. |
|
|
String |
Path to file containing icons to use in shortcut. |
|
|
String |
Path of the application or document to execute. |
|
|
Integer |
Type of Window to display application in. 1 for normal, 2 for minimized, and 3 for maximized Window. |
|
|
String |
Default working directory for application to use. |
Once you have set the parameters for the shortcut, invoke the
Save method to save and update the shortcut.
'create a shortcut on desktop linked to hello script Set objShell = CreateObject("Wscript.Shell") strDesktop = objShell.SpecialFolders("Desktop") 'get path to desktop Set objShortcut = objShell.CreateShortcut(strDesktop & "\nlink.lnk") objShortcut.TargetPath = "D:\heh.vbs" 'script to execute objShortcut.Save 'save ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access