1

We have a python script that needs to trigger the open of the Microsoft Store. We believe that the easiest way to do that is to use the ms-windows-store:// protocol.

We're currently doing that like this

import subprocess
ret = subprocess.call(["start", "ms-windows-store://pdp/?ProductId=9WZDNCRFHVJL"], shell=True)

Is that the recommended way to do this? I'm not sure if using start is correct here, or if there's something better?

  • `subprocess` can be used to run commands via Python. I your case if `start windows-store://pdp/?ProductId=9WZDNCRFHVJL` is a correct command, it is correct. For detailed info on parameters of subprocess call, see this answer: https://stackoverflow.com/a/15109975/4636715 – vahdet Feb 07 '20 at 06:06
  • Thank you! That’s exactly what I was looking for. – Tony Ferrell Feb 07 '20 at 08:27

1 Answers1

3

Use os.startfile("ms-windows-store://pdp/?ProductId=9WZDNCRFHVJL"). This calls WINAPI ShellExecuteW directly. If you use subprocess, you have the expense of starting a child process. Plus CMD's start command will first search PATH to find a file that it can execute. Presuming nothing is found (and nothing likely will be, given this name), it hands the request off to ShellExecuteExW to let the OS shell handle it.

Eryk Sun
  • 33,190
  • 5
  • 92
  • 111