简体   繁体   English

有没有办法检查.ahk 脚本是否通过 Python 运行?

[英]Is there a way to check if .ahk script is running through Python?

I tried to create a Python script that goes through all my autohotkey scripts and runs them if they aren't running.我尝试创建一个 Python 脚本,该脚本遍历我所有的自动热键脚本并在它们未运行时运行它们。 This was simple enough for scripts converted into executables, but I haven't been able to find a way to see if.ahk scripts are running.这对于转换为可执行文件的脚本来说已经足够简单了,但是我还没有找到一种方法来查看是否正在运行.ahk 脚本。 I tried using python autohotkey libraries, but I haven't managed to find any with this functionality.我尝试使用 python 自动热键库,但我还没有找到任何具有此功能的库。

How would this be possible using Python?使用 Python 这怎么可能?

The processes are all going to be named AutoHotkey.exe, but they were all started with different arguments.这些进程都将被命名为 AutoHotkey.exe,但它们都以不同的 arguments 启动。 The first (and by default the only) argument is going to be a path to the script that's running.第一个(默认情况下也是唯一的)参数将是正在运行的脚本的路径。

You can check this for example with the task manager, just enable the commandline column in the processes tab.例如,您可以使用任务管理器检查这一点,只需启用进程选项卡中的命令行列。 Alternatively, you can use eg ProcessExplorer to see it even easier.或者,您可以使用例如ProcessExplorer来更轻松地查看它。

And about getting the commandline in Python, I don't know Python, but you're likely going to want to useWMI / (C) .关于在 Python 中获取命令行,我不知道 Python,但您可能会想要使用WMI / (C)
Easiest way is probably going to be using some Python WMI library.最简单的方法可能是使用一些 Python WMI 库。 A Google search gives me this one , probably worth taking a look at.谷歌搜索给了我这个,可能值得一看。

Here's an example PowerShell command for using WMI to get the commandlines:这是使用 WMI 获取命令行的示例 PowerShell 命令:

Get-WmiObject Win32_Process -Filter "name = 'AutoHotkey.exe'" | Format-List -Property CommandLine

Wouldn't be too hard to parse the desired info from that either, if doing it properly gets too complicated.如果正确执行它变得太复杂,那么从中解析所需的信息也不会太难。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM