將快捷方式對象保存到磁盤中。
object.Save
使用 CreateShortcut 方法創(chuàng)建快捷方式對象并設置快捷方式對象的屬性后,必須用 Save 方法將快捷方式對象保存到磁盤中。Save 方法使用快捷方式對象的 FullName 屬性中的信息,確定快捷方式對象在磁盤上的保存位置。只可創(chuàng)建系統(tǒng)對象的快捷方式,包括文件、目錄和驅(qū)動器(不包括打印機鏈接或調(diào)度任務)。
下面的示例演示如何將一個 .wsf 文件用于以不同腳本語言(VBScript 和 Jscript)寫成的兩個作業(yè)。每個作業(yè)都創(chuàng)建正在運行腳本的快捷方式,并創(chuàng)建 www.microsoft.com 的 URL 快捷方式。
<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>
運行腳本 | WshShortcut 對象 | WshUrlShortcut 對象 | FullName 屬性 | TargetPath 屬性 | WindowStyle 屬性 | Hotkey 屬性 | IconLocation 屬性 | Description 屬性 | WorkingDirectory 屬性