@echo off
setlocal

:ValidateArgs
if [%1] == [] goto Usage

:LocalConfig
set RegRoot=HKCU
set DeleteKeys=0
if /i [%1] == [delete] (
    set DeleteKeys=1
) else (
    if /i [%1] == [hklm] set RegRoot=HKLM
)
if /i [%2] == [delete] (
    set DeleteKeys=1
)

@REM CLSID 65A...
@REM 
:Execute
set DeviceAppName=4ndeva32.exe
set CLSID=65A59365-B7AF-460a-A733-9DB503B16EAF
set InterfaceId=D51A9C23-3C57-4cdf-B419-FB662276870A
set EventInterfaceId=37CFDA83-14C3-475E-91C4-93EB05C658B9
set LibId=3794F27B-F75E-4565-ABCB-5D57E48BF50C
set ClassName=ANDevice.ANDev

call :RegQuery "%RegRoot%\Software\Classes\CLSID\{%CLSID%}"
call :RegQuery "%RegRoot%\Software\Classes\Interface\{%InterfaceId%}"
call :RegQuery "%RegRoot%\Software\Classes\Interface\{%EventInterfaceId%}"
call :RegQuery "%RegRoot%\Software\Classes\%ClassName%"
call :RegQuery "%RegRoot%\Software\Classes\%ClassName%.1"
call :RegQuery "%RegRoot%\Software\Classes\TypeLib\{%LibId%}"
goto Cleanup


:RegQuery
@REM Technique 1: Use appropriate reg.exe for 32-bit context
set RegCmd=%SYSTEMROOT%\system32\reg.exe
if exist %SYSTEMROOT%\syswow64 set RegCmd=%SYSTEMROOT%\syswow64\reg.exe
if %DeleteKeys% == 1 (
    %RegCmd% delete %1 /f
) else (
    %RegCmd% query %1 /s || echo Missing key: %1
)

@REM @REM Technique 2: Use /reg:32 argument to force 32-bit registry access
@REM if %DeleteKeys% == 1 (
@REM     reg delete %1 /reg:32 /f
@REM ) else (
@REM     reg query %1 /reg:32 /s || echo Missing key: %1
@REM )

goto Cleanup


:Usage
echo %~n0 HIVE_ABBREVIATION [delete]
echo Examples:
echo  %~n0 hkcu
echo  %~n0 hkcu delete
echo  %~n0 hklm
echo  %~n0 hklm delete


:Cleanup
endlocal
