Process, Wait with multiple processes

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
andr3as
Posts: 2
Joined: 24 Mar 2017, 06:09

Process, Wait with multiple processes

24 Mar 2017, 06:18

I want to make a script to wait for several task manager programs to run and then force reboot
for example in one process it is working perfectly

Code: Select all

#NoTrayIcon
#Persistent
Process, Wait, anvir.exe
shutdown, 6
but i want at the same script to insert and

Code: Select all

anvir.exe 
procexp64.exe
procexp.exe
Procmon.exe
SystemExplorer.exe
ProcessLasso.exe
ProcessGovernor.exe
Taskmgr.exe
i tried different ways but the script does not respond

Any help would be much appreciated
Thank you in advance
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: Process, Wait with multiple processes

24 Mar 2017, 14:25

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)

}
my scripts

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], Joey5 and 263 guests