I've got another WMI demo for COMate; it enumerates the printers on the system.
I just used the demo file "Demo_MonitorInfo.pb" as template, and combined it with information from a 
post on the German PB forum by scholly. Although I don't know too much about COM and WMI, it seems that with good information from these sources I managed to create a new demo for COMate. 

It works fine 
here (Windows XP Pro SP3), it would be good if someone with appropriate knowledge checks the code, though:
Code: Select all
IncludePath "..\..\"
XIncludeFile "COMate.pbi"
Procedure Get_Printers() 
   Protected objWMIService.COMateObject, printer.COMateObject
   Protected colPrinter.COMateEnumObject 
   strComputer.s = "." 
   Net_I_Index$ = Str(Interface_Index) 
   objWMIService = COMate_GetObject("winmgmts:\\" + strComputer + "\root\cimv2", "") 
   If objWMIService 
      colPrinter = objWMIService\CreateEnumeration("ExecQuery('Select * FROM Win32_Printer')") 
      If colPrinter 
         printer = colPrinter\GetNextObject() 
         While printer 
            Debug "Name        =  " + printer\GetStringProperty("Name")
            Debug "Attributes   =  " + Str(printer\GetIntegerProperty("Attributes")) 
            Debug "----------------------------------------------------------------"
            printer\Release() 
            printer = colPrinter\GetNextObject() 
         Wend 
         colPrinter\Release() 
      EndIf 
      objWMIService\Release()  
   EndIf 
EndProcedure 
Get_Printers()
I learned another interesting point from the post mentioned above: We can use this code to check whether a printer is online or offline. Just run the code above with your printers switched off, and save the attribute values. When the printers are on, their attribute values have changed.
For instance, the above code returns the following output on my system:
Name  =  EPSON Stylus DX4000 Series
Attributes   =  3660
Then I can use the following code to check the status of this printer:
Code: Select all
IncludePath "..\..\"
XIncludeFile "COMate.pbi"
Procedure.i Check_Printer (name.s, attributes_off) 
   Protected objWMIService.COMateObject, printer.COMateObject
   Protected colPrinter.COMateEnumObject 
   Protected ret = -1           ; return vcalue is undefined in the beginning
   strComputer.s = "." 
   Net_I_Index$ = Str(Interface_Index) 
   objWMIService = COMate_GetObject("winmgmts:\\" + strComputer + "\root\cimv2", "") 
   If objWMIService 
      colPrinter = objWMIService\CreateEnumeration("ExecQuery('Select * FROM Win32_Printer')") 
      If colPrinter 
         printer = colPrinter\GetNextObject() 
         While printer 
            If printer\GetStringProperty("Name") = name
               If printer\GetIntegerProperty("Attributes") = attributes_off
                  ret = 0             ; offline
               Else   
                  ret = 1             ; online
               EndIf
               printer\Release()
               Break
            EndIf 
            printer = colPrinter\GetNextObject() 
         Wend 
         colPrinter\Release() 
      EndIf 
      objWMIService\Release()  
   EndIf 
   
   ProcedureReturn ret
EndProcedure 
Debug Check_Printer("EPSON Stylus DX4000 Series", 3660)
Regards, Little John