【问题标题】:Closing more than one Autohotkeys applications关闭多个 Autohotkeys 应用程序
【发布时间】:2022-01-09 18:07:42
【问题描述】:

我有 4 个应用程序,我必须使用 4 个不同的 autohotkey exe 应用程序才能始终处于最佳状态。但是,我想关闭所有这些或终止它们的进程。 我也尝试使用ESC::ExitApp、Process.Kill() 函数,但只有其中一个正在关闭。

这是我的代码:

#SingleInstance Force

WinSet, AlwaysOnTop, Toggle, Bot
Winset, Style, -0xC00000, Bot

^!p::Pause
*ESC::ExitApp
return

其他应用程序相同但不同的 Windows Title 名称。

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}");

根据上面的代码,我试图杀死 4 个应用程序,但只有一个正在关闭。另外我在 TaskManager 中看不到运行 autohotkeys.exe 文件。有什么办法吗 关闭或关闭所有 autohotkeys.exe 文件?提前谢谢你。

【问题讨论】:

  • 为什么会有多个 AHK 脚本?他们可能只是一个脚本?但是无论如何,您的热键仅在一个脚本中被捕获,因为您正在使用按键。按键只会被一个脚本捕获。您可以在热键中使用~ modifier,这样按键就不会被消耗。

标签: c# autohotkey kill-process


【解决方案1】:

您可以使用 Windows 中的 WMI 来执行此操作。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多