I've written a batch script that checks if Python is installed, if it's not installed - it initiates the Python installer contained in the same folder as itself.
I'm using the following code:
reg query "hkcu\software\Python 2.6"
if ERRORLEVEL 1 GOTO NOPYTHON
:NOPYTHON
ActivePython-2.6.4.8-win32-x86.msi
reg query "hklm\SOFTWARE\ActiveState\ActivePerl\" 1>>Output_%date%_%time%.log 2>&1
if ERRORLEVEL 1 GOTO NOPERL
reg query "hklm\SOFTWARE\Gtk+"
if ERRORLEVEL 1 GOTO NOPYGTK
:NOPERL
ActivePerl-5.10.1.1006-MSWin32-x86-291086.msi 1>>Output_%date%_%time%.log 2>&1
:NOPYGTK
pygtk_windows_installer.exe
But in some cases the installer starts up even if Python is installed. What is the problem here?
For those who just want a simple check if Python is installed and can be executed without going into the registy, in your batch file:
:: Check for Python Installation
python --version 2>NUL
if errorlevel 1 goto errorNoPython
:: Reaching here means Python is installed.
:: Execute stuff...
:: Once done, exit the batch file -- skips executing the errorNoPython section
goto:eof
:errorNoPython
echo.
echo Error^: Python not installed
Your code doesn't branch after the registry query is done. No matter what the first if ERRORLEVEL
evaluates to, the next step is always to step into the :NOPYTHON
label.
Ed: Here is an example how to make it work. The idea is to add another goto statement which will skip the :NOPYTHON
label if desired.
reg query "hkcu\software\Python 2.6"
if ERRORLEVEL 1 GOTO NOPYTHON
goto :HASPYTHON
:NOPYTHON
ActivePython-2.6.4.8-win32-x86.msi
:HASPYTHON
reg query "hklm\SOFTWARE\ActiveState\ActivePerl\" 1>>Output_%date%_%time%.log 2>&1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With