I've a pretty complicated quetions for the community: I have to manage a lab with hundreds of PCs running Win XP Pro SP3. Sometimes students disconnect keyboards and/or mouses from computers so after every class I've to check every single machine and check if they are atteched and this steal me a lot o time. So I'm writing a script in VBScript for checking machines and put infos about configuration into a database that helps me telling if there is something wrong on a machine. Now, I'd like to check, also, if PS2 keyboard and/or PS2 mouse are attached or not so I can immediately restoring them before a new class starts without goin' for attempt, machine by machine. How can I achive this? WMI? How? Thanks.
Asked
Active
Viewed 553 times
1 Answers
1
WMI should probably be able to provide this information. See this related question for examples. You will probably need Win32_Keyboard
and Win32_PointingDevice
, maybe Win32_PnPEntity
if those do not report disconnecting (I cannot test PS/2 hardware).
All this should translate into VBScript, maybe using Microsoft's documentation about WMI from VBScript. For a start:
On Error Resume Next
For Each strComputer In Array("localhost")
WScript.Echo "Computer: " & strComputer
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Keyboard", "WQL", &h30)
For Each objItem In colItems
WScript.Echo objItem.Availability, objItem.Caption, _
objItem.ConfigManagerErrorCode, objItem.ConfigManagerUserConfig, _
objItem.Description, objItem.DeviceID, _
objItem.ErrorCleared, objItem.ErrorDescription, _
objItem.IsLocked, _
objItem.LastErrorCode, _
objItem.Layout, _
objItem.Name, _
objItem.PNPDeviceID, _
objItem.Status, objItem.StatusInfo, _
objItem.SystemCreationClassName, objItem.SystemName
Next
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PointingDevice", "WQL", &h30)
For Each objItem In colItems
WScript.Echo objItem.Availability, objItem.Caption, _
objItem.ConfigManagerErrorCode, objItem.ConfigManagerUserConfig, _
objItem.Description, objItem.DeviceID, _
objItem.DeviceInterface, _
objItem.ErrorCleared, objItem.ErrorDescription, _
objItem.HardwareType, _
objItem.IsLocked, _
objItem.LastErrorCode, _
objItem.Name, _
objItem.PNPDeviceID, _
objItem.PointingType, _
objItem.Status, objItem.StatusInfo, _
objItem.Synch, _
objItem.SystemCreationClassName, objItem.SystemName
Next
Next

Community
- 1
- 1

Michel de Ruiter
- 7,131
- 5
- 49
- 74
-
Many many thanks Michel! It seems working perfectly! I tried on a machine: one time with keyboard and mouse plugged in and I got two msgboxes (one with keyboard data and one with mouse data); one time just with keyboard and I got only the msgbox with keyboard data; one time just with mouse plugged in and I got only the msgbox with mouse data. Thanks again! – user3697206 Oct 07 '15 at 15:38