Reputation: 35
I have 4 applications and I have to use 4 different autohotkey exe applications for always on Top future. However, I would like to close all of them or kill their process.
I tried using ESC::ExitApp
, Process.Kill()
function as well, but only one of them is closing.
Here is my code:
#SingleInstance Force
WinSet, AlwaysOnTop, Toggle, Bot
Winset, Style, -0xC00000, Bot
^!p::Pause
*ESC::ExitApp
return
Other applications are the same but different Windows Title name.
Process[] bottom = Process.GetProcessesByName("bottom");
//MessageBox.Show(workers.Length.ToString());
foreach (Process bot in bottom)
{
bot.Kill();
bot.WaitForExit();
bot.Dispose();
}
Process[] left = Process.GetProcessesByName("left");
//MessageBox.Show(workers.Length.ToString());
foreach (Process l in left)
{
l.Kill();
l.WaitForExit();
l.Dispose();
}
Process[] right = Process.GetProcessesByName("test1");
//MessageBox.Show(workers.Length.ToString());
foreach (Process r in right)
{
r.Kill();
r.WaitForExit();
r.Dispose();
}
Process[] top = Process.GetProcessesByName("top");
//MessageBox.Show(workers.Length.ToString());
foreach (Process t in top)
{
t.Kill();
t.WaitForExit();
t.Dispose();
}
SendKeys.Send("{ESC}");
According to above code, I tried to kill 4 apps but only one is closing. Plus I cannot see in TaskManager running autohotkeys.exe files.Is there any way to turn off or close all autohotkeys.exe files? Thank you in advance.
Upvotes: 0
Views: 165
Reputation: 1153
You can use the WMI from windows to do that.
ESC::
Query := "Select ProcessId, CommandLine from Win32_Process where name = 'Autohotkey.exe'"
for process in ComObjGet("winmgmts:").ExecQuery(Query, "WQL")
process, close, % process.ProcessId
Return
Upvotes: 2