創(chuàng)建新的快捷方式,或打開現有的快捷方式。
object.CreateShortcut(strPathname)
CreateShortcut 方法返回 WshShortcut 對象或 WshURLShortcut 對象。只調用 CreateShortcut 方法并不會導致快捷方式的創(chuàng)建?旖莘绞綄ο笠约皩ζ渌龅母拇鎯υ趦却嬷,直到您用 Save 方法將其保存到磁盤中為止。要創(chuàng)建快捷方式,必須執(zhí)行以下操作:
注意 一個常見的問題是,將參數放在快捷方式對象的 TargetPath 屬性中將不起作用?旖莘绞降乃袇刀急仨毞旁 Arguments 屬性中。
下面的示例創(chuàng)建 WshShell 對象并使用 CreateShortcut 方法創(chuàng)建兩個快捷方式。
<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>