(specifcally mias post that is based on Lexikos code)
All I would like to do is have a gui that lets me start or start this script.
So far what I tried.
Removed #Persistent and then put it in a loop. The problem is I cannot get the loop to break. So i removed the loop idea. I tried to break the loop by adding to the start:
if (runit = 1)
break
And then made the stop button runit = 1 (I added in the script on top (runit =)
All I wish to have done is click start and it will run until I click the stop button? I do not think I ask so much.
Code: Select all
#SingleInstance Force
SetWorkingDir %A_ScriptDir%
Gui Add, Button, x134 y59 w80 h23 gScripStarts, Start
Gui Add, Button, x136 y112 w80 h23 gScriptStop, Stop
Gui Font, cFuchsia, Segoe Script
Gui Add, Text, x96 y33 w120 h23 +0x200, Test of script
Gui Font
Gui Show, w481 h253, Window
Return
ScripStarts:
; ========== START OF SCRIPT ==========
; Get WMI service object.
winmgmts := ComObjGet("winmgmts:")
; Create sink objects for receiving event noficiations.
ComObjConnect(createSink := ComObjCreate("WbemScripting.SWbemSink"), "ProcessCreate_")
ComObjConnect(deleteSink := ComObjCreate("WbemScripting.SWbemSink"), "ProcessDelete_")
; Set event polling interval, in seconds.
interval := 2
; Register for process creation notifications:
winmgmts.ExecNotificationQueryAsync(createSink
, "Select * from __InstanceCreationEvent"
. " within " interval
. " where TargetInstance isa 'Win32_Process'")
; Register for process deletion notifications:
winmgmts.ExecNotificationQueryAsync(deleteSink
, "Select * from __InstanceDeletionEvent"
. " within " interval
. " where TargetInstance isa 'Win32_Process'")
; Don't exit automatically. I commented it out because I want to be able to run it to start and stop
;#Persistent
; Called when a new process is detected:
ProcessCreate_OnObjectReady(obj) {
proc := obj.TargetInstance
TrayTip New Process Detected, % "
(LTrim
ID:`t" proc.ProcessID "
Parent:`t" proc.ParentProcessID "
Name:`t" proc.Name "
Path:`t" proc.ExecutablePath "
Command line (requires XP or later):
" proc.CommandLine
)
}
; Called when a process terminates:
ProcessDelete_OnObjectReady(obj) {
proc := obj.TargetInstance
TrayTip Process Terminated, % "
(LTrim
ID:`t" proc.Handle "
Name:`t" proc.Name
)
}
; ========== END OF SCRIPT ==========
ScriptStop:
;what do i put here
return
GuiEscape:
GuiClose:
ExitApp