Open a shortcut file with subprocess

Viewed 70

I am fairly new to python and have been trying to make a program that will open the Minecraft launcher for me. However, the new launcher exe file is blocked as it is located in the windowsapp file which requires a lot of faffing about that I would rather avoid, so instead I was hoping to see if I could open the desktop shortcut instead to open it? This code so far doesn't work as it gives me the error:

OSError: [WinError 193] %1 is not a valid Win32 application

the code:

import time
import subprocess

subprocess.Popen('C:/Users/(my username)/Desktop/Minecraft Launcher.lnk')

I have tried subprocess.call however that doesn't seem to work either.

1 Answers

.lnk files are interpreted by the shell. So, enable the shell:

subprocess.call("C:\\Users\\My Username\\Desktop\\Minecraft Launcher.lnk", shell=True)

As a side note, the shell is one of the very few things in Windows that insists on backslashes.

Related