我想更改a的图标.lnk
我创建后的文件。到目前为止,这是我的主要代码:
import win32com.client
shell = win32com.client.Dispatch("WScript.Shell")
shortcut = shell.CreateShortCut("shortcut.lnk")
shortcut.Targetpath = "C:\\Users\Benjie\AppData\Local\Programs\Python\Python36\python.exe"
shortcut.save()
这创建了一个带有 python 图标的快捷方式,但我想将其更改为不同的图标,如果可能的话,更改为不同的图标.exe
文件。
我怎样才能做到这一点?
我最好使用 Windows api 库之一,但如果不可能,外部库也可以工作。
Thanks
好的,经过几个小时的研究后this https://stackoverflow.com/questions/9081928/how-to-get-attributes-from-win32com-client-dispatchshell-application,我设法找到了我要找的东西:shortcut.IconLocation
。这会将快捷方式的图标设置为 .exe、.dll、.icl 或 .ico 文件中的图标。例如:
import win32com.client
shell = win32com.client.Dispatch("WScript.Shell")
shortcut = shell.CreateShortcut("shortcut.lnk")
shortcut.TargetPath = "C:\\Users\Benjie\AppData\Local\Programs\Python\Python36\python.exe"
shortcut.IconLocation = "C:\path_to_.exe,1"
shortcut.Save()
图标路径是文件的路径,带有逗号和文件中图标的编号。如果您创建快捷方式并在其属性中更改其图标,则可以看到文件的图标,然后浏览找到该文件。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)