暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

使用 Windows 脚本主机创建桌面快捷方式

原创 watson 2023-02-21
567

摘要

WSH 是一种工具,可用于在 Windows 95 或 Windows NT 4.0 上以本机方式在基本操作系统中运行 Microsoft Visual Basic Scripting Edition 和 JScript。 它还包括几种 COM 自动化方法,可让你通过 Windows 脚本主机对象模型轻松执行多个任务。 Microsoft Windows 脚本主机集成到 Windows 98、Windows 2000 及更高版本的 Windows 操作系统中。 它通过安装 Windows NT 4.0 选项包可用于 Windows NT 4.0。 若要下载此工具,请访问 脚本

使用 WSH 创建桌面快捷方式的示例

此程序演示如何使用 Windows 脚本主机在 Windows 桌面上创建快捷方式。 若要运行此示例,必须在计算机上安装 Windows 脚本主机。 若要运行其中一个示例,请将下面的代码复制到新的程序文件中并运行它。

示例 1

Visual Basic 脚本

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:添加命令行参数

Visual Basic 脚本

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 快捷方式

Visual Basic 脚本

WshShell = CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
oUrlLink = WshShell.CreateShortcut(strDesktop+"\Microsoft Web Site.URL")
oUrlLink.TargetPath = "http://www.microsoft.com"
oUrlLink.Save

 备注

若要创建快捷方式,必须为所有方法传递有效参数。 如果其中一个参数不正确,则不会出现错误。

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论