I'm trying to combine 2 detection/monitoring scripts created by jNizM. Example 1 and 2 on this page. The scripts monitor processes and Plug and Play devices.
viewtopic.php?f=83&t=105171
The script break when trying to add a line. I tried a few things, but wasn't able to find the solution. More precision in the script's comments. Thanks in advance for any help.
Code: Select all
#NoEnv
#SingleInstance, Force
SendMode Input
SetWorkingDir %A_ScriptDir%
CoordMode, ToolTip
Gui, Gui1:New
Gui, Font, s10
Gui, Add, ListView, w900 h600, EventType|Time|Name|DeviceID|ProcessID
for k, v in ["80", "50", "160", "359", "80"]
LV_ModifyCol(k, v)
Gui, Show
;=============================================================================================
WMI := ComObjGet("winmgmts:")
ComObjConnect(Sink := ComObjCreate("WbemScripting.SWbemSink"), "SINK_")
CommandProcess := "WITHIN 1 WHERE TargetInstance ISA 'Win32_Process'"
WMI.ExecNotificationQueryAsync(Sink, "SELECT * FROM __InstanceCreationEvent " . CommandProcess)
WMI.ExecNotificationQueryAsync(Sink, "SELECT * FROM __InstanceDeletionEvent " . CommandProcess)
CommandPnPEntity := "WITHIN 1 WHERE TargetInstance ISA 'Win32_PnPEntity'"
WMI.ExecNotificationQueryAsync(Sink, "SELECT * FROM __InstanceCreationEvent " . CommandPnPEntity)
WMI.ExecNotificationQueryAsync(Sink, "SELECT * FROM __InstanceDeletionEvent " . CommandPnPEntity)
;=============================================================================================
SINK_OnObjectReady(Obj)
{
TI := Obj.TargetInstance
If (Obj.Path_.Class = "__InstanceCreationEvent")
EventType := "Created"
If (Obj.Path_.Class = "__InstanceDeletionEvent")
EventType := "Terminated"
FormatTime, Time,, HH:mm
strToolTip := "
(
Name: " TI.Name "
EventType: " EventType "
Time: " Time "
)"
ToolTip, % strToolTip, 0, 0
; ----> The script stop displaying "Processes instance events" when trying to add "DeviceID: " TI.DeviceID " in "strToolTip".
Gui, Gui1:Default
LV_Insert(1,, EventType, Time, TI.Name) ; ----> or stop displaying "Processes instance events" when trying to add ", TI.DeviceID" in the ListView.
}