创建新的快捷方式,或打开现有的快捷方式。
object.CreateShortcut(strPathname)
CreateShortcut 方法返回 WshShortcut 对象或 WshURLShortcut 对象。只调用 CreateShortcut 方法并不会导致快捷方式的创建。快捷方式对象以及对其所做的更改存储在内存中,直到您用 Save 方法将其保存到磁盘中为止。要创建快捷方式,必须执行以下操作:
注意 一个常见的问题是,将参数放在快捷方式对象的 TargetPath 属性中将不起作用。快捷方式的所有参数都必须放在 Arguments 属性中。
下面的示例创建 WshShell 对象并使用 CreateShortcut 方法创建两个快捷方式。
<package> <job id="vbs"> <script language="VBScript"> set WshShell = WScript.CreateObject("WScript.Shell") strDesktop = WshShell.SpecialFolders("Desktop") set oShellLink = WshShell.CreateShortcut
(strDesktop & "\Shortcut Script.lnk") oShellLink.TargetPath = WScript.ScriptFullName oShellLink.WindowStyle = 1 oShellLink.Hotkey = "CTRL+SHIFT+F" oShellLink.IconLocation = "notepad.exe, 0" oShellLink.Description = "Shortcut Script" oShellLink.WorkingDirectory = strDesktop oShellLink.Save set oUrlLink = WshShell.CreateShortcut
(strDesktop & "\Microsoft Web Site.url") oUrlLink.TargetPath = "http://www.microsoft.com/china" oUrlLink.Save </script> </job> <job id="js"> <script language="JScript"> var WshShell = WScript.CreateObject("WScript.Shell"); strDesktop = WshShell.SpecialFolders("Desktop"); var oShellLink = WshShell.CreateShortcut
(strDesktop + "\\Shortcut Script.lnk"); oShellLink.TargetPath = WScript.ScriptFullName; oShellLink.WindowStyle = 1; oShellLink.Hotkey = "CTRL+SHIFT+F"; oShellLink.IconLocation = "notepad.exe, 0"; oShellLink.Description = "Shortcut Script"; oShellLink.WorkingDirectory = strDesktop; oShellLink.Save(); var oUrlLink = WshShell.CreateShortcut
(strDesktop + "\\Microsoft Web Site.url"); oUrlLink.TargetPath = "http://www.microsoft.com/china"; oUrlLink.Save(); </script> </job> </package>