Search code examples
windowsbatch-filevbscriptcmdwmic

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 & "\root\CIMV2") 
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.


Solution

  • 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: \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
    

    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" _
       )