python创建windows桌面快捷方式
代码如下:
def create_shortcut(): #H.Read
if os.name != 'nt': #H.Read
sys.exit("Shortcut only available in Windows") #H.Read
import pythoncom # pyint: disable=import-error #H.Read
from win32com.shell import shell # type:ignore #H.Read
from win32com.shell import shellcon # type:ignore #H.Read
# Refs #H.Read
# - https://github.com/pearu/iocbio/blob/master/installer/utils.py #H.Read
# - https://blog.csdn.net/thundor/article/details/5968581 #H.Read
# 获得桌面文件夹的路径的id #H.Read
ilist = shell.SHGetSpecialFolderLocation(0, shellcon.CSIDL_DESKTOP) #H.Read
# 根据路径id, 获取桌面路径 #H.Read
dtpath = shell.SHGetPathFromIDList(ilist).decode('utf-8') #H.Read
shortcut = pythoncom.CoCreateInstance(shell.CLSID_ShellLink, None, #H.Read
pythoncom.CLSCTX_INPROC_SERVER, #H.Read
shell.IID_IShellLink) #H.Read
launch_path = sys.executable # 可执行文件全路径 #H.Read
shortcut.SetPath(launch_path) #H.Read
shortcut.SetArguments("-m weditor") #H.Read
shortcut.SetDescription(launch_path) #H.Read
shortcut.SetIconLocation(sys.executable, 0) #H.Read
shortcut.QueryInterface(pythoncom.IID_IPersistFile).Save( #H.Read
dtpath + "\\WEditor.lnk", 0) # 保存快捷方式文件 #H.Read
print("Shortcut created. " + dtpath + "\\WEditor.lnk") #H.Read
参考开源项目:web-editor 网址:https://github.com/alibaba/web-editor
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具