【发布时间】:2018-11-12 19:24:08
【问题描述】:
我找到了这段代码,但它不再在 Windows 10 和 Python 3.7.1 上运行:
import win32com.client
import pythoncom
import os
# pythoncom.CoInitialize() # remove the '#' at the beginning of the line if running in a thread.
desktop = r'C:\Users\XXXXX\Desktop' # path to where you want to put the .lnk
path = os.path.join(desktop, 'NameOfShortcut.lnk')
target = r'C:\Users\XXXXX\Desktop\muell\picture.gif'
icon = r'C:\Users\XXXXX\Desktop\muell\icons8-link-512.ico' # not needed, but nice
shell = win32com.client.Dispatch("WScript.Shell")
shortcut = shell.CreateShortCut(path)
shortcut.Targetpath = target
shortcut.IconLocation = icon
shortcut.WindowStyle = 7 # 7 - Minimized, 3 - Maximized, 1 - Normal
shortcut.save()
是否有类似(或更简单)的方法来创建 Windows 快捷方式?
【问题讨论】:
-
代码怎么跑不了?这只是Python。如果您安装了 Python,它应该仍然可以运行。
-
是的,但没有。
-
那么“不运行”是什么意思呢?什么都没有发生?
-
我自己发现了问题:目标错了。这是正确的行:target = r'C:\Program Files (x86)\Microsoft Office\Office16\EXCEL.EXE'
标签: python python-3.x windows shortcut