Platforms to show: All Mac Windows Linux Cross-Platform

/Win/WMI/WMI Query


Required plugins for this example: MBS Win Plugin

Last modified Sat, 8th Aug 2025.

You find this example project in your MBS Xojo Plugin download as a Xojo project file within the examples folder: /Win/WMI/WMI Query

Download this example: WMI Query.zip

Project "WMI Query.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
Sub Constructor() // required for Windows 8.1 or later Call WindowsWMIMBS.InitSecurity(False) End Sub
End Class
Class Window1 Inherits Window
Control query Inherits TextField
ControlInstance query Inherits TextField
End Control
Control List Inherits Listbox
ControlInstance List Inherits Listbox
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() run End EventHandler
End Control
Control PopupMenu1 Inherits PopupMenu
ControlInstance PopupMenu1 Inherits PopupMenu
EventHandler Sub Change() if me.ListIndex>=0 then query.text=me.text PushButton1.Push end if End EventHandler
End Control
Control PopupMenu2 Inherits PopupMenu
ControlInstance PopupMenu2 Inherits PopupMenu
EventHandler Sub Change() if TargetWin32 then w=new WindowsWMIMBS if w.ConnectServer("root\"+PopupMenu2.text) then 'MsgBox "Connected" run else MsgBox "ConnectServer: fail"+EndOfLine+"Lasterror: "+str(w.Lasterror) end if end if End EventHandler
End Control
Control StaticText1 Inherits Label
ControlInstance StaticText1 Inherits Label
End Control
EventHandler Sub Open() if TargetWin32 then w=new WindowsWMIMBS if w.ConnectServer("root\"+PopupMenu2.text) then 'MsgBox "Connected" else MsgBox "ConnectServer: fail"+EndOfLine+"Lasterror: "+str(w.Lasterror) end if else MsgBox "This example is for Windows only." end if End EventHandler
Function St(v as Variant) As string If v.IsArray Then Var s() As String Select Case v.ArrayElementType Case Variant.TypeString s = v Case Variant.TypeInt32 Var values() As Int32 = v For Each va As Int32 In values s.append va.ToString Next Case Variant.TypeInt64 Var values() As Int64 = v For Each va As Int64 In values s.append va.ToString Next Case Variant.TypeBoolean Var values() As Boolean = v For Each va As Boolean In values s.append va.ToString Next Case Variant.TypeSingle Var values() As Single = v For Each va As Single In values s.append va.ToString Next Case Variant.TypeDouble Var values() As Double = v For Each va As Double In values s.append va.ToString Next Else Break // todo? End Select Return Join(s,", ") End If Return v.StringValue Exception t As TypeMismatchException // ignore End Function
Sub run() list.DeleteAllRows if w.query("WQL",query.text) then 'MsgBox "query: ok" while w.NextItem dim s(-1) as string = w.GetNames for each t as string in s List.AddRow t List.Cell(List.LastIndex,1)=st(w.GetProperty(t)) List.Cell(List.LastIndex,2)=hex(w.GetPropertyType(t))+" "+w.GetPropertyTypeString(t) next wend else MsgBox "query: fail"+EndOfLine+"Lasterror: "+str(w.Lasterror) end if End Sub
Property w As WindowsWMIMBS
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
Sign
End Sign
End Project

See also:

Download this example: WMI Query.zip

The items on this page are in the following plugins: MBS Win Plugin.


The biggest plugin in space...