(view source code of getdeviceclassguid.bat as plain text)
@ECHO OFF
ECHO "%~1" | FIND.EXE "/" >NUL && GOTO Syntax
IF NOT "%~2"=="" IF /I NOT "%~2"=="/Q" GOTO Syntax
IF NOT "%~3"=="" GOTO Syntax
SETLOCAL ENABLEDELAYEDEXPANSION
SET Quiet=0
SET RC=0
SET Underline========================================
IF "%~1"=="" (
SET ClassName=
SET Quiet=0
) ELSE (
SET ClassName=%~1
IF /I "%~2"=="/Q" SET Quiet=1
)
IF "%ClassName%"=="" (
(
ECHO.
ECHO Choose a device class from the left column of the following list, then run
ECHO this batch file again using the selected device class as command line
ECHO argument to list all associated Devic Interface GUIDs
ECHO E.g. "%~n0" HIDClass
ECHO.
DevCon.exe classes | FIND.EXE /V /I "listing " | SORT.EXE
) | MORE
) ELSE (
IF "%Quiet%"=="0" (
REM Verbose output
FOR /F "tokens=1,2* delims=: " %%A IN ('DevCon.exe find ^=%ClassName% ^| FIND.EXE ":"') DO (
ECHO.%%C
ECHO.%Underline%
SET %%C.=
SET Count=0
FOR /F "tokens=2 delims={}" %%D IN ('REG.EXE Query "HKLM\SYSTEM\CurrentControlSet\Control\DeviceClasses" /f "%%~A" /s') DO (
SET GUID={%%D}
REM Convert to upper case
SET GUID=!GUID:a=A!
SET GUID=!GUID:b=B!
SET GUID=!GUID:c=C!
SET GUID=!GUID:d=D!
SET GUID=!GUID:e=E!
SET GUID=!GUID:f=F!
SET %%C.{%%D}=!GUID!
SET GUID=
SET /A Count += 1
)
IF !Count! EQU 0 (
SET %%C.{%Random%}=--No Class GUID found--
)
FOR /F "tokens=2 delims==" %%E IN ('SET "%%~C.{" 2^>NUL') DO (
ECHO.%%E
SET %%~C.%%E=
)
SET /A RC += !Count!
ECHO.
ECHO.
)
) ELSE (
REM Quiet mode
FOR /F "tokens=1,2* delims=: " %%A IN ('DevCon.exe find ^=%ClassName% ^| FIND.EXE ":"') DO (
FOR /F "tokens=2 delims={}" %%D IN ('REG.EXE Query "HKLM\SYSTEM\CurrentControlSet\Control\DeviceClasses" /f "%%~A" /s') DO (
SET GUID={%%D}
REM Convert to upper case
SET GUID=!GUID:a=A!
SET GUID=!GUID:b=B!
SET GUID=!GUID:c=C!
SET GUID=!GUID:d=D!
SET GUID=!GUID:e=E!
SET GUID=!GUID:f=F!
SET QuietList.!GUID!=!GUID!
SET GUID=
)
)
SET RC=0
FOR /F "tokens=2 delims==" %%E IN ('SET QuietList. 2^>NUL') DO (
ECHO.%%E
SET QuietList.%%E=
SET /A RC += 1
)
)
)
ENDLOCAL & EXIT /B %RC%
:Syntax
ECHO.
ECHO GetDeviceClassGUID.bat, Version 2.00 for Windows 10
ECHO List Device Interface GUID(s) for the specified device class
ECHO.
ECHO Usage: GetDeviceClassGUID.bat [ DeviceClass [ /Q ] ]
ECHO.
ECHO Where: DeviceClass is a device class short name (run batch without
ECHO arguments to list all device classes available)
ECHO /Q Quiet mode (list Device Interface GUIDs only)
ECHO.
ECHO Notes: This batch file uses Microsoft's DEVCON tool to list available
ECHO device classes, see https://www.robvanderwoude.com/devcon.php
ECHO Return code ("ErrorLevel") equals the number of Device
ECHO Interface GUIDs found, or 0 if no command line argument was
ECHO supplied (list mode), or -1 in case of command line errors.
ECHO.
ECHO Written by Rob van der Woude
ECHO https://www.robvanderwoude.com
EXIT /B -1
page last modified: 2024-04-16; loaded in 0.0097 seconds