简体   繁体   中英

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. 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. I tried using python autohotkey libraries, but I haven't managed to find any with this functionality.

How would this be possible using Python?

The processes are all going to be named AutoHotkey.exe, but they were all started with different 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.

And about getting the commandline in Python, I don't know Python, but you're likely going to want to useWMI / (C) .
Easiest way is probably going to be using some Python WMI library. 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:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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