On Mac and Linux you can run
pkill -f "(chrome)?(--headless)"
to kill all headless Chrome instances.
I'd like something similar that will run on Windows.
command linegoogle-chrome
On Mac and Linux you can run
pkill -f "(chrome)?(--headless)"
to kill all headless Chrome instances.
I'd like something similar that will run on Windows.
Best Answer
Unfortunately,
CommandLine
is not easily retrievable through the normal process management commands, so we need to dip into WMI. This tends to make the command more complex, but you can alias it or hide it in a script/function you can reuse.Here's an example of how you can do this in PowerShell:
Generalising it a bit, we can also get:
Alternatively,
Name
can use a looser matching, or we can filter purely on the CommandLine like you're currently doing:More generally, you can extend it to a cmdlet via script: https://technet.microsoft.com/en-us/library/ff677563.aspx
The same process applies if you want to do this in cmd, except you'd need to grab the PIDs from the output of
wmic
and pass it intotaskkill
.