You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Win/WMI/WMI Recent Windows Events
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 List Inherits Listbox
ControlInstance List Inherits Listbox
End Control
EventHandler Sub Open()
if TargetWin32 then
// init and connect
w=new WindowsWMIMBS
if w.ConnectServer("root\cimv2") then
// query number of records
if w.query("WQL","Select * from Win32_NTEventLogFile Where LogFileName = 'Application'") then
if w.NextItem then
dim NumberOfRecords as integer = w.GetPropertyInteger("NumberOfRecords")
dim last10 as integer = 0
if NumberOfRecords > 10 then last10 = NumberOfRecords - 10
// now get the newest 10
for i as integer = last10 to NumberOfRecords-1
if w.Query("WQL","Select * from Win32_NTLogEvent Where LogFile = 'Application' AND RecordNumber =" +str(i)) then
if w.NextItem then
list.AddRow w.GetPropertyString("ComputerName")
List.Cell(List.LastIndex,1)=str(w.GetPropertyInteger("EventCode"))
List.Cell(List.LastIndex,2)=w.GetPropertyString("Message")
end if
end if
next
else
MsgBox "NextItem: fail"+EndOfLine+"Lasterror: "+str(w.Lasterror)
end if
else
MsgBox "query: fail"+EndOfLine+"Lasterror: "+str(w.Lasterror)
end if
else
MsgBox "ConnectServer: fail"+EndOfLine+"Lasterror: "+str(w.Lasterror)
end if
else
MsgBox "This example is for Windows only."
end if
End EventHandler
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