[Tutor] Batch file to detect if Python is installed

Alan G alan.gauld at freenet.co.uk
Fri Sep 2 20:13:09 CEST 2005


> Does anyone know of a cunning method to detect whether Python is
> installed using a batch file?

Search the registry using the reg command:


------------------ DOS session -------------
C:\WINDOWS>reg query "hkcu\software\Pytho"

Error:  The system was unable to find the specified registry key or 
value

C:\WINDOWS>reg query "hkcu\software\Python"

! REG.EXE VERSION 3.0

HKEY_CURRENT_USER\software\Python

C:\WINDOWS>

---------------------------------------------

Next question - How to detect that you got a result other than an 
error?

Use ERRORLEVEL

ERRORLEVEL will return 0 if the last command had no errors
or an error number otherwise.

Thus something like:

@ECHO OFF
reg query "hkcu\software\Python"
if ERRORLEVEL 1 GOTO NOPYTHON
python myscrip.py
...
GOTO :EOF
:NOPYTHON
REM use dos commands here


> P.S. I do realise this is a little off topic... It does involve 
> Python
> and programming... just not programming in Python.

Seems relevant to me... BUT if you can be sure Windows Host Scripting 
is
installed ands active that is much much easier to use...

Alan G.



More information about the Tutor mailing list