| 1 |
:: Check if a registry key and, optionally, an attribute is available in the registry. |
| 2 |
:: Return 0 if the key/attribute is installed, 2 otherwise. |
| 3 |
:: Usage |
| 4 |
:: isInstalled.bat key [attributeName attributeValue] |
| 5 |
|
| 6 |
@echo off |
| 7 |
SetLocal EnableExtensions |
| 8 |
|
| 9 |
Set key=%1 |
| 10 |
|
| 11 |
:: if no attribute name is supplied, only check the key |
| 12 |
If "%2"=="" Goto check_key |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
:check_attribute |
| 17 |
Set attribute=%2 |
| 18 |
Set value=%3 |
| 19 |
|
| 20 |
:: query registry and get the second and third token, which is the type and the value |
| 21 |
For /F "usebackq tokens=2,3" %%A In (`reg query "%key%" /v "%attribute%" 2^>nul ^| find "%attribute%"`) Do ( |
| 22 |
Set type=%%A |
| 23 |
Set value_actual=%%B |
| 24 |
) |
| 25 |
|
| 26 |
If "REG_DWORD"=="%type%" ( |
| 27 |
:: convert hex to int value |
| 28 |
Set /A value_actual=%value_actual% |
| 29 |
) |
| 30 |
|
| 31 |
If Not %value_actual% Equ %value% exit /B 2 |
| 32 |
exit /B 0 |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
:check_key |
| 37 |
reg query "%key%" >nul 2>nul |
| 38 |
If Errorlevel 1 exit /B 2 |
| 39 |
|
| 40 |
exit /B 0 |