python没有文件自动创建快捷方式_使用Python在Windows 7中创建快捷方式文件

旧的,但我仍然希望发布一个答案,以帮助任何可能有相同问题且需要代码示例的人.

首先,使用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,我不希望控制台一直弹出.我还没有尝试过一个没有安慰的程序.

希望这可以帮助!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值