On a database, I can get a list of all the currently running processes, and the sql command that kicked them off.
I'd like to do a similar thing on a windows box.
I can get the list of processes, but not the command line that kicked them off.
My question is: Given a PID on Windows - how do I find the command line instruction that executed it?
Assumptions:
- Windows 7 and equivalent servers
Powershell and WMI.
Or
Note that you have to have permissions to access this information about a process. So you might have to run the command as admin if the process you want to know about is running in a privileged context.
You can use the WMI subsystem, using WMIC.EXE to get to this information. Assuming a PID of 600:
You can also search for name, or other characteristic of the process. Use this command to list all attributes:
The other answers are certainly good options that will serve you well in an automated system because of their command line nature (and I see from the tag that that's what you wanted). Of course, some folks might want to explore this kind of info with a GUI, so here's an alternative along those lines.
Process Explorer is a Sysinternals tool maintained by Microsoft. It can display the command line of the process in the process's properties dialog as well as the parent that launched it, though the name of that process may no longer be available. Here's the process properties dialog:
If you want a more detailed audit trail of when a process was launched and under what conditions, you can turn to another Sysinternals tool called Process Monitor. Here you can filter for "Process started" events, learn about the environment the process was launched in, and see what other events were occurring around that time. It's quite a powerful program. Here's the event properties dialog:
To complement Ryan Ries' helpful PowerShell answer with a shorter alternative via the
-Filter
parameter that also usesGet-CimInstance
instead of the deprecated-since-v3Get-WmiObject
cmdlet.The
-Filter
parameter essentially allows you to pass theWHERE
clause of a WQL statement instead of passing a full query statement via-Query
.