Wijsmullerbros.nl

Why do you want to leave me? Why? I'm sorry I'm not real. If you let me, I'll be so real for you!

— David (A.I.)

May
5

I was in need of a way to kill processes from the windows command line. The normal ways of doing so either require the process id (PID) or the process name.

When running java programs, the name will always be java.exe, so that does not help a lot.
I was looking for a way to kill processes, selecting by the command line options used to start the process. For instance: java.exe MyFavoriteMain -cp /somedirectory/matchthis/*

It turns out that doing this with the regular commands, is very difficult, if not impossible.
After searching, talking to Windows power user friends, I came to the following solution!

wmic PROCESS WHERE "Commandline LIKE '%matchthis%'" CALL Terminate

A little obscure if you ask me, but it does the job.

Oh and when using this inside a batch script, you'll need to duplicate the % signs, or else the interpreter will use these instead of passing them literally to be used as regex pattern.