0

I have a script running in AutoHotkey called BasicTools.ahk; it is process that runs under autohotkey.exe. When I run Get-Process it only shows me instances of Autohotkey so I have no way to isolate the specific process running my script (all I see from Get-Process is multiple Autohotkey processes). I saw answers like this, but they are not usable for this specific situation.

How can I stop a specific script (from PowerShell) that is running under Autohotkey, knowing the name of the script (in this case BasicTools.ahk)?

YorSubs
  • 3,194
  • 7
  • 37
  • 60
  • 2
    Have you looked at the command-line of the ahk process? `Get-WmiObject Win32_Process -Filter "name = 'autohotkey.exe'" | Select -Expand CommandLine` or if you already have a process from `Get-Process` use: `Get-WmiObject Win32_Process -Filter "ProcessId = $($proc.Id)" | Select -Expand CommandLine` – zett42 Oct 06 '22 at 15:41
  • 2
    In PS 7.x: `Get-Process autohotkey | select -expand CommandLine` – zett42 Oct 06 '22 at 15:43
  • That's great on PS 7, but sadly, I have to use a lot of Windows servers in enterprise environments, and PS 5.1 will be the standard there for the next 3-4 years I think. The `Get-WmiObject` is perfect, but is that ok to use, as I'm sure I've seen people saying that we should stop using Wmi and move over to Cim? – YorSubs Oct 06 '22 at 15:57
  • 1
    AFAIK WMI isn't deprecated. I don't have experience of using WMI/CIM in enterprise environment. I'd say use what works best for you. From [this blog post](https://devblogs.microsoft.com/scripting/should-i-use-cim-or-wmi-with-windows-powershell/), a major difference is the protocol (DCOM for WMI and WSMAN for CIM), so one or the other might be easier on your corporate firewall. – zett42 Oct 06 '22 at 16:16
  • Is having the script close itself on command out of the question? What I'm thinking is that maybe you can have one script communicate with the other and tell the other to exit. Take a look at [this answer](https://stackoverflow.com/a/36240299/4190564), along with the other answers to that question. – Darin Oct 07 '22 at 00:40

0 Answers0