Question

I'm creating a GPO to check if a registry value exists on 32 and 64 bit machines. I rather only create one script, instead of two. The script should check the value of a key, if it's a certain text, then exit, if not, delete the value.

I thought reg query would work, but that does not query the key.

KEY: HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\DirectX
OR KEY: >HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\DirectX

VALUE: 00 00 00 09 1A

If that value exist, leave it, if not, delete it.

echo off

reg query HKLM\SOFTWARE\Wow6432Node\Microsoft\CCM\Security<br>
if %errorlevel% == 1 goto not_64bit

reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\CCM\Security" /v AllowedRootCAHashCode /t REG_SZ /d "00 00 00 09 1A"
if %errorlevel% == 0 goto end
Reg Delete HKLM\SOFTWARE\Wow6432Node\Microsoft\CCM\Security /v AllowedRootCAHashCode /t 
goto end

:not_64bit
reg query "HKLM\SOFTWARE\Microsoft\CCM\Security" /v AllowedRootCAHashCode /t REG_SZ /d "00 00 00 09 1A"
if %errorlevel% == 0 goto end
Reg Delete HKLM\SOFTWARE\Microsoft\CCM\Security /v AllowedRootCAHashCode /f

:end

No correct solution

OTHER TIPS

This may help - it's not tested.

@echo off

reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\CCM\Security" >nul 2>&1 || goto not_64bit
reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\CCM\Security" /v AllowedRootCAHashCode /t REG_SZ |find "00 00 00 09 1A" >nul
if errorlevel 1 Reg Delete "HKLM\SOFTWARE\Wow6432Node\Microsoft\CCM\Security" /v AllowedRootCAHashCode /f
goto :EOF

:not_64bit
reg query  "HKLM\SOFTWARE\Microsoft\CCM\Security" /v AllowedRootCAHashCode /t REG_SZ |find "00 00 00 09 1A" >nul 2>&1 && goto :EOF
Reg Delete "HKLM\SOFTWARE\Microsoft\CCM\Security" /v AllowedRootCAHashCode /f

This did the trick ...

@echo off

reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\CCM\Security" || goto not_64bit

reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\CCM\Security" /v AllowedRootCAHashCode /t REG_SZ |findstr -i /c:"065fac" || goto 64bitkey
goto :end

:64bitkey
Reg Add "HKLM\SOFTWARE\Wow6432Node\Microsoft\CCM\Security" /v AllowedRootCAHashCode /t REG_SZ /d " " /f
goto :end

:not_64bit
reg query  "HKLM\SOFTWARE\Microsoft\CCM\Security" /v AllowedRootCAHashCode /t REG_SZ |findstr -i /c:"065fac" || goto 32bitkey
goto :end

:32bitkey
Reg Add "HKLM\SOFTWARE\Microsoft\CCM\Security" /v AllowedRootCAHashCode /t REG_SZ /d " " /f

:end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top