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 and ...
Get Windows XP in a Nutshell, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.