Last active
February 3, 2022 13:30
-
-
Save lboulard/ad92244bb518b7171e0daf38c8cbfaba to your computer and use it in GitHub Desktop.
Get Python executable paths
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION | |
@SET "HKEY=HKEY_LOCAL_MACHINE\Software\Python\PythonCore" | |
@ECHO.::::::::: Local Machine | |
@CALL :display "HKEY_LOCAL_MACHINE\Software\Python\PythonCore" | |
@ECHO.::::::::: Current User | |
@CALL :display "HKEY_CURRENT_USER\Software\Python\PythonCore" | |
@FOR /F "usebackq" %%v in (`py.exe -c "import sys;print(sys.winver)"`) DO @SET "VERSION=%%v" | |
@ECHO.::::::::: py.exe current version | |
@ECHO Current version: Python %VERSION% | |
@GOTO :EOF | |
:display | |
@FOR /F "usebackq skip=2 tokens=1,2*" %%A IN (`REG QUERY %HKEY% 2^>nul`) DO @( | |
ECHO.%%A | FIND /I "%HKEY%\" >nul 2>nul && ( | |
@CALL :show "%%A" "%HKEY%\" | |
) | |
) | |
@GOTO :EOF | |
:show | |
@SET "V=%~1" | |
@SET "V=!V:%~2=!" | |
@SET "HKEY2=%HKEY%\%V%" | |
@FOR /F "usebackq skip=2 tokens=1,2*" %%A IN (`REG QUERY %HKEY2% /v Version 2^>nul`) DO @( | |
ECHO.%%A: "%%C" | |
) | |
@FOR /F "usebackq skip=2 tokens=1,2*" %%A IN (`REG QUERY %HKEY2%\InstallPath /v *ExecutablePath 2^>nul`) DO @( | |
IF /I "%%A" == "ExecutablePath" ECHO.Console: "%%C" | |
IF /I "%%A" == "WindowedExecutablePath" ECHO.Windows: "%%C" | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment