python篇--创建桌面快捷方式

创建快捷方式

import os
from win32com.client import Dispatch

def create_shortcut(target_path, shorcut_path):
    shell = Dispatch('WScript.Shell')
    shortcut = shell.CreateShortcut(shorcut_path)
    shortcut.TargetPath = target_path
    shortcut.Save()

if __name__ == '__main__':
    desktop_path = os.path.join(os.path.expanduser('~'), 'Desktop')
    target_path = r'E:\Work\space\raspberry\test.py'
    shortcut_path = os.path.join(desktop_path, 'Shortcut.lnk')
    create_shortcut(target_path, shortcut_path)

 

快捷方式-属性-目标修改为    %windir%\system32\cmd.exe /k python test.py debug

posted @ 2024-04-28 14:12  夜未央leo  阅读(62)  评论(0编辑  收藏  举报