I am running couple of wmic commands in a btach file to find a process and killing it.
wmic Path win32_process Where "CommandLine Like '%app1%'" Call Terminate
wmic Path win32_process Where "CommandLine Like '%app2%'" Call Terminate
These commands run fine when I run from console individually but when I run them using a batch file , I get error as below:
wmic Path win32_process Where "CommandLine Like ''" Call Terminate
No Instance(s) Available.
Can someone point out whats the issue with the command if its run from a batch file.
Open a command prompt. Type WMIC to invoke the program, and hit enter. This will give you the WMIC command prompt, wmic:root\cli> From here, you can run WMI queries.
The WMI command-line (WMIC) utility provides a command-line interface for Windows Management Instrumentation (WMI). WMIC is compatible with existing shells and utility commands.
What is WMIC? The Windows Management Instrumentation (WMI) Command-Line Utility (WMIC) is a command-line utility that allows users to perform WMI operations from a command prompt. WMI is an interface providing a variety of Windows management functions.
Wmic is an external command that is available for the following Microsoft operating systems. In Windows 10 and Windows 11, it is located at C:\Windows\System32\wbem\WMIC.exe.
Inside a batch file percent signs need to be escaped. The command you are trying to execute are seeing %app1%
as a variable read and replaced with (probably) a empty string.
You need to use
wmic Path win32_process Where "CommandLine Like '%%app1%%'" Call Terminate
Note that this condition will also match the current wmic
instance, as the search term is also included in its own command line. You should add an aditional test to ensure only the desired process is terminated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With