Platforms to show: All Mac Windows Linux Cross-Platform
Required plugins for this example: MBS Win Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Win/WMI/WMI File Events
This example is the version from Fri, 12th Aug 2021.
Project "WMI File Events.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Löschen"
Const kFileQuit = "Beenden"
Const kFileQuitShortcut = ""
Sub Constructor()
// required for Windows 8.1 or later
Call WindowsWMIMBS.InitSecurity(False)
End Sub
End Class
Class MainWindow Inherits Window
Control List Inherits Listbox
ControlInstance List Inherits Listbox
End Control
Control Timer1 Inherits Timer
ControlInstance Timer1 Inherits Timer
EventHandler Sub Action()
dim found as Boolean = false
while w.NextItem
found = true
List.AddRow "got event "+str(Ticks)
dim s() as string = w.GetNames
dim o as WMIObjectMBS = w.GetPropertyObject("TargetInstance")
if o<>Nil then
List.AddRow "Type: "+o.GetPropertyString("__CLASS")
List.AddRow "Name: "+o.GetPropertyString("Name")
end if
wend
if found then
me.Period = 100
else
me.Period = 1000
end if
End EventHandler
End Control
EventHandler Sub Open()
dim query as string
// Watch for file events
dim folder as FolderItem = SpecialFolder.Desktop
dim path as string = folder.NativePath
dim drive as string = left(path,2)
dim rest as string = mid(path,3)
rest = ReplaceAll(rest, "\", "\\")
query = "SELECT * FROM __InstanceOperationEvent WITHIN 1 WHERE TargetInstance ISA 'CIM_DataFile' AND TargetInstance.Drive='"+drive+"' AND TargetInstance.Path='"+rest+"'"
w = new WindowsWMIMBS
if not w.ConnectServer("root\cimv2") then
MsgBox "Failed to connect."
elseif not w.ExecNotificationQueryAsync("WQL", query) then
MsgBox "Failed to run query."
else
// ok
timer1.Mode = 2
end if
End EventHandler
Property w As WindowsWMIMBS
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&Ablage"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Bearbeiten"
MenuItem EditUndo = "&Rückgängig"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "&Ausschneiden"
MenuItem EditCopy = "&Kopieren"
MenuItem EditPaste = "&Einfügen"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "&Alles auswählen"
End MenuBar
End Project
See also:
- /Win/WMI/WMI HDD Info
- /Win/WMI/WMI Network Test
- /Win/WMI/WMI Process CPU usage
- /Win/WMI/WMI Process Creation Events
- /Win/WMI/WMI Process Creation Events via Remote
- /Win/WMI/WMI Processor
- /Win/WMI/WMI Query
- /Win/WMI/WMI Recent Windows Events
- /Win/WMI/WMI Recent Windows Events Web
- /Win/WMI/WMI Wireless LAN Signal Strength
The items on this page are in the following plugins: MBS Win Plugin.