旧的,但我仍然希望发布一个答案,以帮助任何可能有相同问题且需要代码示例的人.
首先,使用pip install pywin32下载pywin32或下载sourceforge二进制文件或pywin32 wheel文件和pip install.
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\Public\Desktop' # path to where you want to put the .lnk
path = os.path.join(desktop, 'NameOfShortcut.lnk')
target = r'C:\path\to\target\file.exe'
icon = r'C:\path\to\icon\resource.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()
当我有一个带调试控制台的GUI时,我使用了WindowStyle,我不希望控制台一直弹出.我还没有尝试过一个没有安慰的程序.
希望这可以帮助!