使用 Windows Scripting Host 中的 WshShortcut 获取快捷方式的信息

Windows Scripting Host 为我们提供了一个 WshShortcut 对象,可以使用此对象来创建快捷方式或获取快捷方式的信息

WshShortcut 有以下属性:
TargetPath:获取或设置快捷方式指向的目标文件的路径
FullName:获取或设置快捷方式的路径
Description:获取或设置快捷方式的说明
IconLocation:获取或设置快捷方式图标的位置
WindowStyle:获取或设置启动目标程序时所使用的窗口样式
HotKey:获取或设置用于启动目标程序的热键,只热键只能激活 WINDOWS 桌面和开始菜单中的快捷方式
WorkingDirectory:获取或设置目标程序的工作目录
Arguments:获取一个 WshArgument 对象的集合

WshShortcut 对象还有一个 Save 方法,用来保存快捷方式

不能直接 new 一个 WshShortcut 对象,需要使用 WshShell 对象的 CreateShortcut 方法:

WshShell shell = new WshShell();
WshShortcut link = shell.CreateShortcut("path"); // 如果指定的路径存在,则使用这此信息来创建一个 WshShortcut 对象
string targetPath = link.TargetPath; // 获取信息

link.Description = "使用程序设置的说明";
link.Save(); // 保存信息

如果需要在 .NET 中使用的话,需要在 COM 活页中引用 “Windows Scripting Host Object Model” 组件
posted @ 2008-04-13 20:16  匡匡  阅读(648)  评论(2编辑  收藏  举报