Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect Python when installed as a Store app #5189

Closed
zooba opened this issue Mar 22, 2019 · 2 comments

Comments

Projects
None yet
3 participants
@zooba
Copy link
Member

commented Mar 22, 2019

When Python is installed as a Store app, it does not expose the normal registry keys (because Store apps aren't allowed to write to the regular registry). It does expose the key when queried directly (e.g. as HKCU\Software\Python\PythonCore\3.7), but enumerating HKCU\Software\Python\PythonCore key does not find it (because of deliberate limitations in Windows).

One option is to add an explicit query for 3.7 and later keys, which raises the question of "how much later" (probably stop at 3.9 for now I'd say). Alternatively, it could use the FindPackagesForUser API and checking for publisher id qbz5n2kfra8p0 (alternatively, Package Family Name PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0, but note that this includes the version number, so it would have to be a partial match). The install location should be available as part of this query, and python.exe is in there.

@huguesv

This comment has been minimized.

Copy link
Contributor

commented Apr 17, 2019

Direct query, rather than enumeration, works but all the paths are mangled.

Other non paths string values are correct (like SupportUrl, DisplayName, etc)

Paths read from registry are:

C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1008.0_x64__qbz5n2kfra8p0[                    ]

C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1008.0_x64__qbz5n2kfra8p0python.exe[                    ]

C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1008.0_x64__qbz5n2kfra8p0pythonw.exe[                    ]

Paths on disk are:

C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1008.0_x64__qbz5n2kfra8p0

C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1008.0_x64__qbz5n2kfra8p0\python.exe

C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1008.0_x64__qbz5n2kfra8p0\pythonw.exe

I tried on 2 machines and get similar results where there's an extra [ ] at the end.

That looks like a bug in the code that writes those keys.

I found a sample for the package manager API.
https://code.msdn.microsoft.com/windowsapps/Package-Manager-Inventory-ee821079

Unless you run as admin, you get UnauthorizedException.

That was from a regular non-store console app, it looks like a store app with packageQuery identity could do it, but VS is not a store app...

Note that VS Code can detect it because they look in PATH and C:\Users\huvalo\AppData\Local\Microsoft\WindowsApps is in PATH, and that folder contains python.exe, which links to the real file at C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1008.0_x64__qbz5n2kfra8p0\python.exe

@huguesv

This comment has been minimized.

Copy link
Contributor

commented Apr 17, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.