使用子进程打开Windows快捷键文件`.lnk`

发布于 2025-02-09 01:52:51 字数 504 浏览 2 评论 0原文

我是Python的新手,并且一直在尝试制作一个将为我打开“ Minecraft Launcher”的程序。

但是,上下文

,新的启动器.exe文件被阻止,因为它位于WindowsApp文件中,它需要大量的操作,我宁愿避免使用,因此我希望我是否可以打开桌面快捷方式而不是直接打开发射器?

到目前为止,

此代码无法正常工作,因为它给了我错误:

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

我尝试过的代码

import time
import subprocess

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

subprocess.call,但是这似乎也行不通。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白首有我共你 2025-02-16 01:52:51

.lnk文件由外壳解释。因此,启用外壳:

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

作为旁注,壳是窗户中坚持反斜线的几件事之一。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文