@echo off
setlocal

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

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

:Execute
if /i [%DeviceAppType%] == [g] (
    set DeviceAppName=uagrdev
    set CLSID=3F52625C-F66C-43F5-B538-CDF7331E0B7D
    set InterfaceId=D178FEAC-4969-45b4-92BF-4582EA5C6F47
    set EventInterfaceId=FDE206D5-EB3E-4DB1-AC3E-6CF314417443
    set LibId=FB2C3447-9D8D-4AD0-9234-A163505FC3AE
    set ClassName=QWDevice.QWDev
) else (
    set DeviceAppName=uasrdev
    set CLSID=35578409-F9F5-43e8-A6BD-8B77199ED854
    set InterfaceId=6B15E61A-381F-41e7-8B65-BA386473FE8C
    set EventInterfaceId=17DCFB07-18A9-4ffe-B34D-37B91D809C41
    set LibId=CD886C7B-B61C-49cf-B3B8-90DB303A502A
    set ClassName=QSRDevice.QSRDev
)
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 deviceapptype [delete]
echo Examples:
echo  %~n0 s
echo  %~n0 g
echo  %~n0 g delete


:Cleanup
endlocal
