@ECHO OFF :: No command line arguments allowed IF NOT "%~1"=="" GOTO Syntax :: Elevated privileges are required OPENFILES.EXE >NUL 2>&1 || GOTO Syntax SETLOCAL ENABLEDELAYEDEXPANSION :: 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) SET Tab= % :: Convert ConnectorType numbers to descriptions SET ConnectorType.0=PS/2 SET ConnectorType.1=Serial SET ConnectorType.2=USB :: Convert HardwareType numbers to descriptions SET HardwareType.0=Standard Mouse SET HardwareType.1=Standard Pointer SET HardwareType.2=Standard Absolute Pointer SET HardwareType.3=Tablet SET HardwareType.4=Touch Screen SET HardwareType.5=Pen SET HardwareType.6=Track Ball SET HardwareType.256=Other :: Count mice instances SET MiceCount=0 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 ( SET MiceCount=%%A ) :: Show number of detected mice IF %MiceCount% EQU 0 ( ECHO No mouse detected ENDLOCAL & EXIT /B 0 ) IF %MiceCount% EQU 1 ( ECHO 1 mouse detected: ) ELSE ( ECHO %MiceCount% mice detected: ) :: Display mouse properties SET NewLine=0 FOR /F "tokens=*" %%A IN ('WMIC.EXE /Namespace:\\root\WMI Path MSMouse_PortInformation Get * /Format:Value ^| FIND.EXE "="') DO ( FOR /F "tokens=1* delims==" %%B IN ("%%~A") DO ( IF DEFINED %%B.%%C ( ECHO.%Tab%%%B=!%%B.%%C! ) ELSE ( ECHO.%Tab%%%A ) IF "%%~B"=="InstanceName" ECHO. ) ) :: Done ENDLOCAL & EXIT /B %MiceCount% :Syntax ECHO. ECHO HasMouse.bat, Version 1.01 for Windows 7 and later ECHO Check the actual number of mice available at this very moment ECHO. ECHO Usage: HasMouse.bat ECHO. ECHO Notes: This batch file requires elevated privileges. ECHO The return code ("ErrorLevel") equals the number of matching mice ECHO detected, or -1 in case of command line or access denied errors. ECHO. ECHO Written by Rob van der Woude ECHO https://www.robvanderwoude.com EXIT /B -1