創(chuàng)建新的快捷方式,或打開(kāi)現(xiàn)有的快捷方式。
object.CreateShortcut(strPathname)
CreateShortcut 方法返回 WshShortcut 對(duì)象或 WshURLShortcut 對(duì)象。只調(diào)用 CreateShortcut 方法并不會(huì)導(dǎo)致快捷方式的創(chuàng)建?旖莘绞綄(duì)象以及對(duì)其所做的更改存儲(chǔ)在內(nèi)存中,直到您用 Save 方法將其保存到磁盤(pán)中為止。要?jiǎng)?chuàng)建快捷方式,必須執(zhí)行以下操作:
注意 一個(gè)常見(jiàn)的問(wèn)題是,將參數(shù)放在快捷方式對(duì)象的 TargetPath 屬性中將不起作用?旖莘绞降乃袇(shù)都必須放在 Arguments 屬性中。
下面的示例創(chuàng)建 WshShell 對(duì)象并使用 CreateShortcut 方法創(chuàng)建兩個(gè)快捷方式。
<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>
運(yùn)行腳本 | WshShortcut 對(duì)象 | WshUrlShortcut 對(duì)象 | WshShell 對(duì)象