0

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

  • Here is an alternative question, that may even lead to a better solution: [How do I find out which process has a file open?](https://blogs.msdn.microsoft.com/oldnewthing/20120217-00/?p=8283) And the answer is: Use the [Restart Manager](https://msdn.microsoft.com/en-us/library/windows/desktop/cc948910.aspx). – IInspectable Jul 27 '16 at 21:27
  • This looks very neat, although seems a bit too much given I am currently using a BAT and PHP file –  Jul 27 '16 at 22:09
  • If you can switch to using [PowerShell](https://msdn.microsoft.com/en-us/powershell/mt173057.aspx) instead of batch files, this would be a viable option. Even if with lots of P/Invoke calls. – IInspectable Jul 27 '16 at 22:19

1 Answers1

1
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 =, <>, <, >, <=, =>.