The easiest way to close/kill a process in AutoIt is:
ProcessClose(“process_name.exe”)
This works fine if there is only one instance of that particular process, but if you have more than one instance, it will close only one of them.
To close all active process instances you can run following:
Local $process = ProcessList(“process_name.exe”)
For $i = 1 To $process[0][0]
ProcessClose($process[$i][1])
Next
On the first line, function ProcessList returns a two dimensional array with process names and PIDs. Since we are passing a process name, it will only return values for a process with the specified name.
[0][0] – Number of processes
[1][0] – 1st Process name
[1][1] – 1st Process PID
[2][0] – 2nd Process name
[2][1] – 2nd Process PID
…
The very first member of the array [0][0] identifies how many instances of the process in question there are. This is used on the second line to run the cycle as many times as there are active processes.
The third line sends ProcessClose command with PID for each active process.
Windows 7 SP1
AutoIt 3.3
Leave a Reply