如何获取鼠标的唯一ID

How to get unique id of a mouse

我想获得一个鼠标的唯一标识,前提是实验室中每个鼠标品牌都相同。 我试过使用 WMIC 来获取设备属性。我的 VBS 脚本是这样的:

strComputer = "." 
Set objWMIService = GetObject("winmgmts:\" & strComputer & "\root\CIMV2") 
Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM Win32_PointingDevice",,48) 

 Wscript.Echo "DeviceID: " & objItem.DeviceID

我试过用不同的鼠标品牌生成这个脚本,它输出一个唯一的设备 ID。但是当我使用相同的 model/brand 鼠标时,会生成相同的设备 ID。请帮我找到一个唯一的数据,用于识别实验室中的每只老鼠。

我认为 Thangadurai 的评论是正确的,请回答您原来的问题...但是,您可以尝试找到所需的 鼠标 ID 运行ning 下一个代码片段。

最简单的解决方案wmic

wmic path  Win32_PointingDevice get * /FORMAT:Textvaluelist.xsl

关于与 vbScript 相同的输出:如果另存为 28273913.vbs,则使用 cscript 28273913.vbs

' VB Script Document
option explicit
' NameSpace: \root\CIMV2 Class : Win32_PointingDevice
' D:\VB_scripts_help\Scriptomatic
' 

On Error GOTO 0

Dim arrComputers, strComputer, objWMIService, colItems, objItem
Dim strPowerManagementCapabilities

arrComputers = Array(".")
   WScript.Echo "NameSpace: \root\CIMV2 Class : Win32_PointingDevice"
For Each strComputer In arrComputers
   WScript.Echo "..."
   WScript.Echo "=========================================="
   WScript.Echo "Computer: " & strComputer
   WScript.Echo "=========================================="

   Set objWMIService = GetObject("winmgmts:\" & strComputer & "\root\CIMV2")
   Set colItems = objWMIService.ExecQuery( _
          "SELECT * FROM Win32_PointingDevice", "WQL", _
              wbemFlagReturnImmediately + wbemFlagForwardOnly)

   For Each objItem In colItems
      WScript.Echo "Availability: " & objItem.Availability
      WScript.Echo "Caption: " & objItem.Caption
      WScript.Echo "ConfigManagerErrorCode: " & objItem.ConfigManagerErrorCode
      WScript.Echo "ConfigManagerUserConfig: " & objItem.ConfigManagerUserConfig
      WScript.Echo "CreationClassName: " & objItem.CreationClassName
      WScript.Echo "Description: " & objItem.Description
      WScript.Echo "DeviceID: " & objItem.DeviceID
      WScript.Echo "DeviceInterface: " & objItem.DeviceInterface
      WScript.Echo "DoubleSpeedThreshold: " & objItem.DoubleSpeedThreshold
      WScript.Echo "ErrorCleared: " & objItem.ErrorCleared
      WScript.Echo "ErrorDescription: " & objItem.ErrorDescription
      WScript.Echo "Handedness: " & objItem.Handedness
      WScript.Echo "HardwareType: " & objItem.HardwareType
      WScript.Echo "InfFileName: " & objItem.InfFileName
      WScript.Echo "InfSection: " & objItem.InfSection
      WScript.Echo "InstallDate: " & WMIDateStringToDate(objItem.InstallDate)
      WScript.Echo "IsLocked: " & objItem.IsLocked
      WScript.Echo "LastErrorCode: " & objItem.LastErrorCode
      WScript.Echo "Manufacturer: " & objItem.Manufacturer
      WScript.Echo "Name: " & objItem.Name
      WScript.Echo "NumberOfButtons: " & objItem.NumberOfButtons
      WScript.Echo "PNPDeviceID: " & objItem.PNPDeviceID
      WScript.Echo "PointingType: " & objItem.PointingType
      If Isnull( objItem.PowerManagementCapabilities) Then
        strPowerManagementCapabilities=""
      Else
        strPowerManagementCapabilities=Join(objItem.PowerManagementCapabilities, ",")
      End If
         WScript.Echo "PowerManagementCapabilities: " & strPowerManagementCapabilities
      WScript.Echo "PowerManagementSupported: " & objItem.PowerManagementSupported
      WScript.Echo "QuadSpeedThreshold: " & objItem.QuadSpeedThreshold
      WScript.Echo "Resolution: " & objItem.Resolution
      WScript.Echo "SampleRate: " & objItem.SampleRate
      WScript.Echo "Status: " & objItem.Status
      WScript.Echo "StatusInfo: " & objItem.StatusInfo
      WScript.Echo "Synch: " & objItem.Synch
      WScript.Echo "SystemCreationClassName: " & objItem.SystemCreationClassName
      WScript.Echo "SystemName: " & objItem.SystemName
      WScript.Echo "."
   Next
Next

Function WMIDateStringToDate(dtmDate)
    WMIDateStringToDate = ( Left(dtmDate, 4) & "/" & _
    Mid(dtmDate, 5, 2) & "/" & Mid(dtmDate, 7, 2) _
    & " " & Mid (dtmDate, 9, 2) & ":" & Mid(dtmDate, 11, 2) & ":" & Mid(dtmDate,13, 2))
End Function

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

比之前的 wmic 示例更复杂,提供了 运行 一步针对更多计算机的可能性。注意 arrComputers = Array(".") 行。这里 "." 表示 This computer 并且可以用计算机名称列表或 IP 地址 重写,例如

arrComputers = Array _
   ( "computer_1_name" _
   , "computer_2_IP" _
   , "computer_3_name" _
   )