【问题标题】:Open a Windows shortcut file `.lnk` with subprocessOpen a Windows shortcut file `.lnk` with subprocess
【发布时间】:2022-12-28 03:41:14
【问题描述】:

I am fairly new to Python and have been trying to make a program that will open the "Minecraft launcher" for me.

Context

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 the launcher directly?

Error

This code so far doesn't work as it gives me the error:

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

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.

【问题讨论】:

    标签: python windows subprocess lnk


    【解决方案1】:

    .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.

    【讨论】:

      猜你喜欢
      • 2022-12-02
      • 1970-01-01
      • 2022-12-02
      • 2022-12-28
      • 2020-10-06
      • 1970-01-01
      • 1970-01-01
      • 2022-12-27
      • 2022-12-27
      相关资源
      最近更新 更多