Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for getdeviceclassguid.bat

(view source code of getdeviceclassguid.bat as plain text)

  1. @ECHO OFF
  2. ECHO "%~1" | FIND.EXE "/" >NUL && GOTO Syntax
  3. IF NOT "%~2"=="" IF /I NOT "%~2"=="/Q" GOTO Syntax
  4. IF NOT "%~3"=="" GOTO Syntax
  5.  
  6. SETLOCAL ENABLEDELAYEDEXPANSION
  7. SET Quiet=0
  8. SET RC=0
  9. SET Underline========================================
  10.  
  11. IF "%~1"=="" (
  12. 	SET ClassName=
  13. 	SET Quiet=0
  14. ) ELSE (
  15. 	SET ClassName=%~1
  16. 	IF /I "%~2"=="/Q" SET Quiet=1
  17. )
  18.  
  19. IF "%ClassName%"=="" (
  20. 	(
  21. 		ECHO.
  22. 		ECHO Choose a device class from the left column of the following list, then run
  23. 		ECHO this batch file again using the selected device class as command line
  24. 		ECHO argument to list all associated Devic Interface GUIDs
  25. 		ECHO E.g.  "%~n0"  HIDClass
  26. 		ECHO.
  27. 		DevCon.exe classes | FIND.EXE /V /I "listing " | SORT.EXE
  28. 	) | MORE
  29. ) ELSE (
  30. 	IF "%Quiet%"=="0" (
  31. 		REM Verbose output
  32. 		FOR /F "tokens=1,2* delims=: " %%A IN ('DevCon.exe find ^=%ClassName% ^| FIND.EXE ":"') DO (
  33. 			ECHO.%%C
  34. 			ECHO.%Underline%
  35. 			SET %%C.=
  36. 			SET Count=0
  37. 			FOR /F "tokens=2 delims={}" %%D IN ('REG.EXE Query "HKLM\SYSTEM\CurrentControlSet\Control\DeviceClasses" /f "%%~A" /s') DO (
  38. 				SET GUID={%%D}
  39. 				REM Convert to upper case
  40. 				SET GUID=!GUID:a=A!
  41. 				SET GUID=!GUID:b=B!
  42. 				SET GUID=!GUID:c=C!
  43. 				SET GUID=!GUID:d=D!
  44. 				SET GUID=!GUID:e=E!
  45. 				SET GUID=!GUID:f=F!
  46. 				SET %%C.{%%D}=!GUID!
  47. 				SET GUID=
  48. 				SET /A Count += 1
  49. 			)
  50. 			IF !Count! EQU 0 (
  51. 				SET %%C.{%Random%}=--No Class GUID found--
  52. 			)
  53. 			FOR /F "tokens=2 delims==" %%E IN ('SET "%%~C.{" 2^>NUL') DO (
  54. 				ECHO.%%E
  55. 				SET %%~C.%%E=
  56. 			)
  57. 			SET /A RC += !Count!
  58. 			ECHO.
  59. 			ECHO.
  60. 		)
  61. 	) ELSE (
  62. 		REM Quiet mode
  63. 		FOR /F "tokens=1,2* delims=: " %%A IN ('DevCon.exe find ^=%ClassName% ^| FIND.EXE ":"') DO (
  64. 			FOR /F "tokens=2 delims={}" %%D IN ('REG.EXE Query "HKLM\SYSTEM\CurrentControlSet\Control\DeviceClasses" /f "%%~A" /s') DO (
  65. 				SET GUID={%%D}
  66. 				REM Convert to upper case
  67. 				SET GUID=!GUID:a=A!
  68. 				SET GUID=!GUID:b=B!
  69. 				SET GUID=!GUID:c=C!
  70. 				SET GUID=!GUID:d=D!
  71. 				SET GUID=!GUID:e=E!
  72. 				SET GUID=!GUID:f=F!
  73. 				SET QuietList.!GUID!=!GUID!
  74. 				SET GUID=
  75. 			)
  76. 		)
  77. 		SET RC=0
  78. 		FOR /F "tokens=2 delims==" %%E IN ('SET QuietList. 2^>NUL') DO (
  79. 			ECHO.%%E
  80. 			SET QuietList.%%E=
  81. 			SET /A RC += 1
  82. 		)
  83. 	)
  84. )
  85. ENDLOCAL & EXIT /B %RC%
  86.  
  87.  
  88. :Syntax
  89. ECHO.
  90. ECHO GetDeviceClassGUID.bat,  Version 2.00 for Windows 10
  91. ECHO List Device Interface GUID(s) for the specified device class
  92. ECHO.
  93. ECHO Usage:  GetDeviceClassGUID.bat  [ DeviceClass  [ /Q ] ]
  94. ECHO.
  95. ECHO Where:  DeviceClass    is a device class short name (run batch without
  96. ECHO                        arguments to list all device classes available)
  97. ECHO         /Q             Quiet mode (list Device Interface GUIDs only)
  98. ECHO.
  99. ECHO Notes:  This batch file uses Microsoft's DEVCON tool to list available
  100. ECHO         device classes, see https://www.robvanderwoude.com/devcon.php
  101. ECHO         Return code ("ErrorLevel") equals the number of Device
  102. ECHO         Interface GUIDs found, or 0 if no command line argument was
  103. ECHO         supplied (list mode), or -1 in case of command line errors.
  104. ECHO.
  105. ECHO Written by Rob van der Woude
  106. ECHO https://www.robvanderwoude.com
  107. EXIT /B -1
  108.  

page last modified: 2024-04-16; loaded in 0.0097 seconds