user470760
user470760

Reputation:

Kill specific cmd.exe from BAT file containing string

I am currently running into an issue where a "cmd.exe" process remains active despite a particular service being stopped. This in turn is causing problems for an automated script that performs actions on the folder, preventing it from being renamed/moved/etc.

As my automated script runs from a BAT file, I believe I can kill it with TASKKILL. Using "Process Explorer", I searched for the folder name and it was able to locate the "cmd.exe" that was using it. I am having trouble finding a way to automate this though without some type of "Contains String". My pseudo example is...

taskkill /IM cmd.exe /FI "NAME contains TC38247178584278321320778"
php\php.exe migration.php TC38247178584278321320778

enter image description here

Upvotes: 0

Views: 1711

Answers (1)

user6017774
user6017774

Reputation:

wmic process where "commandline like '%TC38247178584278321320778%'" get name

to see what next command will kill

wmic process where "commandline like '%TC38247178584278321320778%'" call terminate

See wmic /?, wmic process /?, wmic process get /?, wmic process call /?, wmic process set /?, wmic /format /?, wmic /node /?, etc.

Like is % 0 or more characters and _ is a single character. Otherwise =, <>, <, >, <=, =>.

Upvotes: 1

Related Questions