I have a very basic process that I wrote and have been running for years that has worked great, but times have changed as well as needs. Basically the script runs in a loop looking for a process and then if the process does not exist, it starts it and re-checks in a minute. While 1 ; Opens up a WHILE loop, with 1 as a constant, so it is infinite
If Not ProcessExists("myprog.exe") Then WinKill("WindowName")
If Not ProcessExists("myprog.exe") Then Run(@ComSpec & " /c MyBatch.bat ", "C:\TechScripts\", @SW_SHOW)
Sleep (60000) ; Puts the script to sleep for 60 Seconds so it doesn't chew CPU power
WEnd I have to add complexity to this code now as I have a need to watch for 2 of the same process. Thinking about this I will need to find the process and count how many, if less than 2 then execute the WinKill and ComSpec, on next check is still not 2, execute it again. Same loop, same delay, same process, just 2 now. My thought is that I need to create an array, or store into a variable the number of processes running as the process name. Something like: While 1 ; Opens up a WHILE loop, with 1 as a constant, so it is infinite
$count = 2
$list = ProcessList("myprog.exe")
For $i = 0 To UBound($list) -2
Next
If $i < $count Then WinKill("DeadWindowName")
If $i < $count Then Run(@ComSpec & " /c MyBatch.bat ", "C:\TechScripts\", @SW_SHOW)
Sleep (60000) ; Puts the script to sleep for 60 Seconds so it doesn't chew CPU power
WEnd I am not sure my logic is right here though. I know Ubound adds a number for each time it runs, so I am minus 2 to even the number to be accurate, however I am not sure the for loop will operate right in the while loop. Please help.