Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to launch a Window's shortcut using Python

Tags:

python

window

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.

like image 673
Yan Godara Avatar asked Jan 12 '16 06:01

Yan Godara


1 Answers

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)
like image 135
Martin Evans Avatar answered Sep 19 '22 01:09

Martin Evans