I'm trying to do the following query in WMI:
SELECT ProcessID from Win32_Process where CommandLine='C:\Windows\system32\calc.exe'
But I got an "Invalid query" error. I also tried with:
SELECT ProcessID from Win32_Process where CommandLine='C:\\Windows\\system32\\calc.exe'
And still get the same error, also I tried to change the single quotes to double quotes but it didn't work.
Does anybody know if its possible to do that query?
Yes and No. Depends on how calc.exe is spawned. For instance, when I type calc into cmd.exe window, my calc gets a commandline of 'calc'. When I type calc into powershell.exe console, it get's a full path. The Win32_Process 'commandline' variable is not reliable IMO. Here are some differing result to prove my point.
So to make it work you will need an OR clause in your SQL statement, matching 'calc' or "C:\Windows\system32\calc.exe"