简体   繁体   中英

How to launch a Window's shortcut using Python

I want to launch a shortcut named blender.ink located at "D://games//blender.ink" . I have tryed using:-

os.startfile ("D://games//blender.ink")

But it failed, it only launches exe files.

The Python os.startfile function should work fine, but you need to specify a .lnk extension to be a valid Windows shortcut file:

import os

os.startfile (r"D:\games\blender.lnk")

If you need to wait for the application to complete before continuing, then a different approach would be needed as follows:

import win32com.shell.shell as shell
import win32event

se_ret = shell.ShellExecuteEx(fMask=0x140, lpFile=r"D:\games\blender.lnk", nShow=1)
win32event.WaitForSingleObject(se_ret['hProcess'], -1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM