Two examples of using WMI with inversion of control updated for PB10. They allow for simple and easy WMI querying. As a result they are probabbly not the fastest way to do this but I liked the tradeoff of simplicity.

The class version is passed an interface to call for each retrieved item. Below is an example of how to implement an interface.

Class PrintOSInfo 
  Interface IWmiItem 
  Inherit IUnknown 
  
    Method Item(value As IDispatch, wmi As IWmiClass) 
      AddMsg( "OS:.......... " + wmi.GetStr("Caption") ) 
      AddMsg( "Rebooted:.... " + wmi.GetLocalDate("LastBootUpTime") ) 
      AddMsg( "-----------------------------------------" ) 
      AddMsg( "" ) 
    End Method 
  End Interface
End Class

And below is an example of how to invoke WMI.

Dim wmi As IWmiClass 
wmi = Class "WmiClass" 
Dim printOS As IWmiItem 
printOS = Class "PrintOSInfo" 
wmi.Query(".", "SELECT * FROM Win32_OperatingSystem", printOS )

The procedural version is passed the address of a function to call for each retrieved item. Below is an example of how to implement the procedural version.

Sub PrintOsInfo() 
  AddMsg( "OS:.......... " + wmiGetStr("Caption") )
End Sub

And below is an example of how to invoke WMI.

wmiQuery(".", "SELECT * FROM Win32_OperatingSystem", CodePtr(printOsInfo) )