not sure is the better way to do this, but lunch this script it will display a
MsgBox as soon as both Chrome.exe and Notepad.exe exist.
Code: Select all
while not (existAllProcesses(["Notepad.exe", "chrome.exe"]*)) {
sleep, 1000
}
MsgBox, 64,, Notepad.exe and Chrome.exe are running.
return
existAllProcesses(__processes*) {
__wmi := ComObjGet("winmgmts:"), __o := {}, __k := 0
__string := ""
Loop % __processes.MaxIndex()
{
__string .= "Name='"__processes[a_index] . "' OR "
}
__string := RTrim(__string, " OR ") ; make a string that looks like "Name='blabla.exe' OR Name='proc.exe'" see: https://www.w3schools.com/SQl/trysql.asp?filename=trysql_select_where_or for SQL syntax
for __proc in __wmi.ExecQuery("SELECT * FROM Win32_Process WHERE " . __string) { ; see: Lexikos answer @ https://autohotkey.com/board/topic/8228-process-listfile-namescommand-lines/page-2
if not (__o.HasKey(__proc.name))
{
__o[__proc.name] := true
} ; if the process hasn't be yet retrieved add it to __o
}
for __i, __j in __o ; loop __o that means all the processes retrieved
{
if not (__j) ; if it appears that one of the processes in the list passed as variadic parameter doesn't exist returns 0 (false)
return 0
__k++ ; otherwise increment __k
}
return (__k == __processes.MaxIndex()) ? 1 : 0
}
Hope it will help you!
EDIT: here's another (easiest) way to achieve this -- adapted from
Garry script on this thread:
https://autohotkey.com/boards/viewtopic.php?f=5&t=23128
Code: Select all
#NoEnv
#SingleInstance Force
#Persistent
ProcessNames := "chrome.exe|notepad.exe" ; matching processes
while not (allProcessExist(ProcessNames)) {
sleep, 2000 ; check for every 2 seconds
}
MsgBox, 64,, Notepad.exe and Chrome.exe are running.
return
;-------------------
allProcessExist(__processes) {
Loop, Parse, % __processes, |
{
Process, Exist, %A_LoopField%
if not (ErrorLevel) ; if process does not exist returns 0 (false)
return 0
}
return 1 ; else return 1 (true)
}