python生成应用程序的快捷方式

代码:

import os,winshell
from win32com.client import Dispatch

path = r"D:/workspace/wwwroot82/pyjiankong/dist/test.lnk"  # Path to be saved (shortcut)
target = r"D:/workspace/wwwroot82/pyjiankong/dist/test.exe"  # The shortcut target file or folder
work_dir = os.path.dirname(target)  # The parent folder of your file

shell = Dispatch('WScript.Shell')
shortcut = shell.CreateShortCut(path)
shortcut.Targetpath = target
shortcut.WorkingDirectory = work_dir
shortcut.save()

 

执行效果:

 

posted @ 2023-01-12 18:01  河北大学-徐小波  阅读(121)  评论(0编辑  收藏  举报