Is there a way using VBscript to check if PS2 keyboard and/or PS2 mouse are attached to a computer running Windows XP or above?

时间:2015-10-06 08:14:19

标签: vbscript wmi

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.

1 个答案:

答案 0 :(得分:1)

WMI应该可以提供此信息。有关示例,请参阅this related question。如果那些need(我无法测试PS / 2硬件),您可能会do not report disconnecting Win32_KeyboardWin32_PointingDevice,也许Win32_PnPEntity

所有这一切都应该转化为VBScript,可能使用微软的documentation关于WMI from VBScript。首先:

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