Update Barcode Scanner Firmware via Windows Management Instrumentation (WMI) Using a VBScript

Priyanka Shrimali -
4 MIN READ
159
0

 Windows Management Instrumentation (WMI) is an industry-standard from Microsoft for the management of hardware devices, including Zebra   barcode  scanners, in a Windows enterprise computing environment. This blog provides step-by-step guidelines on updating barcode scanner firmware   with Windows Management Instrumentation (WMI) using a VBScript. 

 Guide

    1. Open your favorite text editor, Visual Studio Code, Notepad++, etc.

NOTE Microsoft Visual Studio Code is recommended as it is rich with VBScript supporting extensions. Download the latest version via this link: https://code.visualstudio.com/.

   

   2. Define the host, localhost, or the remote PC.

   A string can define multiple host IPs, including the localhost.

' Remote IP, or the localhost. Define all the IPs in the following Array.
arrComputers = Array("127.0.0.1")

    3. Retrieve an instance of the class.

   The GetObject method is called by WMI to retrieve an instance of a class. Query object that indicates the set of properties to be populated, as       requested by a call to GetObject. 

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")

    4. Executes a WQL query to retrieve objects.

   The ExecQuery method is called by WMI to process a WMI Query Language (WQL) query. Pointer to the context object for this call. This value contains     any IWbemContext properties specified by the client. Also, this pointer must be used as a parameter to any calls back into WMI. 

Set zebraScanners = objWMIService.ExecQuery("SELECT * FROM Symbol_BarcodeScanner", "WQL", _ wbemFlagReturnImmediately + wbemFlagForwardOnly)

    5. Query Zebra scanners and filter the relevant by the scanner properties.

    Set the absolute file path to the firmware DAT file and invoke the UpdateFirmware method. For Each objScanner in Zebra Scanners

If InStr(objScanner.PartNumber, "MP7") then    ‘ Filter by the model number
        ' Set the firmware DAT file path and invoke the method
        Set retVal = objScanner.UpdateFirmware(" ")
  ‘ Handle the return status
if retVal <> 0 then
            Wscript.Echo "     Method Invocation Failed!"
        Else
            Wscript.Echo "     Firmware update started."
        End if
    End if
Next

    6. Firmware update events and launch new firmware in the scanner.

   Listen to all the firmware update events and start the new firmware once the session ends. 

Do While(True)
Set objEv = objEvents.NextEvent(10000)    'General timeout to wait
    
    If (objEv.Type = 1) Then
        Wscript.Echo "Session Started."
    End If
                
    If (objEv.Type = 2) Then 
        Wscript.Echo "Started downloading software component: " & objEv.SoftwareComponent 
    End If
        
    If (objEv.Type = 12) Then
        Wscript.Echo "Ended downloading software component: " & objEv.SoftwareComponent
    End If 
            
    If (objEv.Type = 3) Then 
        Wscript.Echo "Progress: " & objEv.Progress
    End If
        
    If(objEv.Type = 11) Then 
        Wscript.Echo "Session Ended."
                        
        Set zebraScanners  = objWMIService.ExecQuery("SELECT * FROM Symbol_BarcodeScanner", "WQL", _
                                          wbemFlagReturnImmediately + wbemFlagForwardOnly)
           For Each objScanner in zebraScanners 
            'Start new firmware if the scanner serial number matches the session end event serial number
            If (objScanner.SerialNumber = "MP7") Then 
                Wscript.Echo
                    WScript.Echo "     Starting new FW at " & Time
                Wscript.Echo
                    objScanner.StartNewFirmware()
                    
                'Adjust pause for firmware start as needed
                Exit Do         
            End If     
        Next
    End If
        
    If (objEv.Type = 100) Then 
        Wscript.Echo "Error occurred. Firmware update aborted."
        Exit Do         
    End If 
Loop

  All the supported properties by the Zebra WMI Provides are listed on the Developer Guide. Refer to the latest version of the document published     on  Support and Downloads: Scanner SDK for Windows. 
 

profile

Priyanka Shrimali

Please Register or Login to post a reply

0 Replies