Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
234 views
in Technique[技术] by (71.8m points)

windows - How to get unique id of a mouse

I want to get a unique id of a mouse provided that every mouse brand is the same in a laboratory. I have tried using WMIC to get device attributes. My VBS script is this:

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

 Wscript.Echo "DeviceID: " & objItem.DeviceID

I have tried generating this script with different mouse brand and it outputs a unique device id. But when I use the same model/brand of mouse, the same device id is generated. Please help me find a unique data to be used to identify every mouse in a laboratory.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I think Thangadurai is right with his comment do your original question... However, you could try to find desired mouse id running next code snippets.

The simpliest solution with wmic:

wmic path  Win32_PointingDevice get * /FORMAT:Textvaluelist.xsl

About the same output with vbScript: use cscript 28273913.vbs if saved as 28273913.vbs.

' VB Script Document
option explicit
' NameSpace: 
ootCIMV2 Class : Win32_PointingDevice
' D:VB_scripts_helpScriptomatic
' 

On Error GOTO 0

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

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

   Set objWMIService = GetObject("winmgmts:" & strComputer & "
ootCIMV2")
   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

More complex than previous wmic example providing possibility to run it against more computers in one step. Note the arrComputers = Array(".") line. Here "." means This computer and could be rewritten by a list of computer names or IP addresses e.g.

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...