python-3.x - 你如何从 Python 中“启动”一个 Windows 协议?
问题描述
我们有一个 python 脚本需要触发 Microsoft Store 的打开。我们认为最简单的方法是使用ms-windows-store://协议。
我们目前正在这样做
import subprocess
ret = subprocess.call(["start", "ms-windows-store://pdp/?ProductId=9WZDNCRFHVJL"], shell=True)
这是推荐的方法吗?我不确定在start
这里使用是否正确,或者是否有更好的方法?
解决方案
使用os.startfile("ms-windows-store://pdp/?ProductId=9WZDNCRFHVJL")
. 这会直接调用 WINAPI ShellExecuteW
。如果您使用子进程,则需要启动子进程。加上 CMD 的start
命令会首先搜索PATH
找到它可以执行的文件。假设没有找到任何东西(给定这个名称,可能什么也找不到),它会将请求交给ShellExecuteExW
OS shell 来处理它。
推荐阅读
- spring - 此注释不适用于目标“局部变量”
- php - 为什么 PHP 减法给我这个?
- spring - 从 Spring 4 升级到 Spring 5 - NoClassDefFoundError: org/springframework/core/JdkVersion
- linux - 恢复构建
- excel-formula - 是否有将 json 日期转换为日期格式的函数(VB6 或 Excel)
- php - 从 WooCommerce 中的特定国家/地区位置获取运费 ID
- javascript - 是否可以选择忽略 SmoothScroll 导航栏中的一个导航链接?
- android-studio - 如何在评级栏上进行仪器测试
- javascript - 为什么使用 JavaScript 无法复制到剪贴板?
- javascript - Visual Studio Code 中的异步智能感知 节点JS