如何使用腳本宿主創建Windows快捷方式
12/03/2020
本文內容
本文介紹如何通過使用 Microsoft Windows Script Host (WSH) Visual FoxPro 創建桌面快捷方式。
適用于: ?Windows 10 - 所有版本,Windows Server 2012 R2
原始 KB 編號: ? 244677
摘要
WSH 是一種工具,允許你在基本操作系統(Visual Basic 95 或 Windows NT 4.0 上)內部運行 Microsoft Visual Basic Scripting Edition 和 Windows JScript。 它還包括幾種 COM 自動化方法,這些方法允許您通過腳本宿主對象模型輕松地Windows任務。 Microsoft Windows 腳本主機集成到 Windows 98、Windows 2000 及更高版本的 Windows 操作系統中。 它通過安裝 Windows NT 4.0 選項包Windows NT 4.0 版。 若要下載此工具,請訪問 腳本。
使用 WSH 創建桌面快捷方式的示例
此程序演示如何使用腳本Windows在桌面版上創建Windows快捷方式。 若要運行此示例,必須在計算機上安裝Windows腳本主機。 若要運行其中一個示例,將下面的代碼復制到新的程序文件中并運行它。
示例 1
WshShell = CreateObject("Wscript.shell")
strDesktop = WshShell.SpecialFolders("Desktop")
oMyShortcut = WshShell.CreateShortcut(strDesktop + "\Sample.lnk")
oMyShortcut.WindowStyle = 3 &&Maximized 7=Minimized 4=Normal
oMyShortcut.IconLocation = "C:\myicon.ico"
OMyShortcut.TargetPath = "%windir%\notepad.exe"
oMyShortCut.Hotkey = "ALT+CTRL+F"
oMyShortCut.Save
示例 2:添加命令行參數
WshShell = CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
oMyShortCut= WshShell.CreateShortcut(strDesktop+"\Foxtest.lnk")
oMyShortCut.WindowStyle = 7 &&Minimized 0=Maximized 4=Normal
oMyShortcut.IconLocation = home()+"wizards\graphics\builder.ico"
oMyShortCut.TargetPath = "c:\Program Files\Microsoft Visual Studio\VFP98\vfp6.exe"
oMyShortCut.Arguments = '-c'+'"'+Home()+'config.fpw'+'"'
oMyShortCut.WorkingDirectory = "c:\"
oMyShortCut.Save
備注
根據你使用的 Visual FoxPro 版本,你可能需要更改示例 2 中 Visual FoxPro 可執行文件的名稱和路徑。
示例 3:向桌面添加 URL 快捷方式
WshShell = CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
oUrlLink = WshShell.CreateShortcut(strDesktop+"\Microsoft Web Site.URL")
oUrlLink.TargetPath = "http://www.microsoft.com"
oUrlLink.Save
備注
若要創建快捷方式,必須傳遞所有方法的有效參數。 如果其中一個參數不正確,則不出現錯誤。
參考
白皮書:Windows腳本宿主:用于腳本語言的通用腳本編寫主機
技術白皮書Windows腳本宿主程序員參考