Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for hasmouse.bat

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

  1. @ECHO OFF
  2. :: No command line arguments allowed
  3. IF NOT  "%~1"=="" GOTO Syntax
  4. :: Elevated privileges are required
  5. OPENFILES.EXE >NUL 2>&1 || GOTO Syntax
  6.  
  7. SETLOCAL ENABLEDELAYEDEXPANSION
  8.  
  9. :: Tab value is one tab followed by a percent character (which will be ignored but shows that the right hand side of the equation is not empty)
  10. SET Tab=	%
  11.  
  12. :: Convert ConnectorType numbers to descriptions
  13. SET ConnectorType.0=PS/2
  14. SET ConnectorType.1=Serial
  15. SET ConnectorType.2=USB
  16.  
  17. :: Convert HardwareType numbers to descriptions
  18. SET HardwareType.0=Standard Mouse
  19. SET HardwareType.1=Standard Pointer
  20. SET HardwareType.2=Standard Absolute Pointer
  21. SET HardwareType.3=Tablet
  22. SET HardwareType.4=Touch Screen
  23. SET HardwareType.5=Pen
  24. SET HardwareType.6=Track Ball
  25. SET HardwareType.256=Other
  26.  
  27. :: Count mice instances
  28. SET MiceCount=0
  29. FOR /F %%A IN ('WMIC.EXE /Namespace:\\root\WMI Path MSMouse_PortInformation Get /Format:CSV 2^>NUL ^| MORE.COM /E +2 ^| FIND.EXE /C ","') DO (
  30. 	SET MiceCount=%%A
  31. )
  32.  
  33. :: Show number of detected mice
  34. IF %MiceCount% EQU 0 (
  35. 	ECHO No mouse detected
  36. 	ENDLOCAL & EXIT /B 0
  37. )
  38. IF %MiceCount% EQU 1 (
  39. 	ECHO 1 mouse detected:
  40. ) ELSE (
  41. 	ECHO %MiceCount% mice detected:
  42. )
  43.  
  44. :: Display mouse properties
  45. SET NewLine=0
  46. FOR /F "tokens=*" %%A IN ('WMIC.EXE /Namespace:\\root\WMI Path MSMouse_PortInformation Get * /Format:Value ^| FIND.EXE "="') DO (
  47. 	FOR /F "tokens=1* delims==" %%B IN ("%%~A") DO (
  48. 		IF DEFINED %%B.%%C (
  49. 			ECHO.%Tab%%%B=!%%B.%%C!
  50. 		) ELSE (
  51. 			ECHO.%Tab%%%A
  52. 		)
  53. 		IF "%%~B"=="InstanceName" ECHO.
  54. 	)
  55. )
  56.  
  57. :: Done
  58. ENDLOCAL & EXIT /B %MiceCount%
  59.  
  60.  
  61. :Syntax
  62. ECHO.
  63. ECHO HasMouse.bat, Version 1.01 for Windows 7 and later
  64. ECHO Check the actual number of mice available at this very moment
  65. ECHO.
  66. ECHO Usage:   HasMouse.bat
  67. ECHO.
  68. ECHO Notes:   This batch file requires elevated privileges.
  69. ECHO          The return code ("ErrorLevel") equals the number of matching mice
  70. ECHO          detected, or -1 in case of command line or access denied errors.
  71. ECHO.
  72. ECHO Written by Rob van der Woude
  73. ECHO https://www.robvanderwoude.com
  74. EXIT /B -1
  75.  

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