VBS 学习笔记一
条评论- 如果 VBS 文件中含有中文,文件编码一定要改为
GBK或GB2312 -
Special Folder Usage AllUsersDesktopDesktop shortcuts for all users AllUsersProgramsPrograms menu options for all users AllUsersStartMenuStart menu options for all users AllUsersStartupStartup applications for all users DesktopDesktop shortcuts for the current user FavoritesFavorites menu shortcuts for the current user FontsFonts folder shortcuts for the current user MyDocumentsMy Documents menu shortcuts for the current user NetHoodNetwork Neighborhood shortcuts for the current user PrintersPrinters folder shortcuts for the current user ProgramsPrograms menu options for the current user RecentRecently used document shortcuts for the current user SendToSendTo menu shortcuts for the current user StartMenuStart menu shortcuts for the current user StartupStartup applications for the current user TemplatesTemplates folder shortcuts for the current user VBS 创建快捷方式示例:
CreateShortcut.vbs 1
2
3
4
5
6
7
8
9
10Set ws = WScript.CreateObject("WScript.Shell")
Set scut = ws.CreateShortcut("xx.lnk")
scut.TargetPath = "path\to\file"
scut.Arguments = "arg1 arg2"
scut.Description = "description"
scut.HotKey = "CTRL+ALT+Y"
scut.IconLocation = "path\to\icon\file,0"
scut.WindowStyle = 1
scut.WorkingDirectory = "path\to\wd"
scut.Save()类似地,Python 也可实现类似的操作,但有一点需要注意,如果对目录创建快捷方式,其
TargetPath属性中的路径分割符必须是\,所以为安全起见,可对所有链接目标为文件 / 文件夹的字符串的路径分隔符统一使用os.path.abspath转换。如果是/,生成的快捷方式的Target type为File而非File folder,导致双击快捷方式没有反应。CreateShortcut.py 1
2
3
4
5
6
7
8
9
10import win32com.client
import os.path
shell = win32com.client.Dispatch('WScript.Shell')
scut = shell.CreateShortcut('xx.lnk')
scut.TargetPath = os.path.abspath('path/to/file')
scut.Description = 'xx'
scut.IconLocation = 'path/to/icon,0'
scut.WindowStyle = 1
scut.HotKey = 'CTRL+ALT+Y'
scut.Save()