18

I want to display a process's command line (including any arguments) from the command line itself. In other words, I want to show the "Command Line" column in the Task Manager but from a command line. Is this possible?

For example, the output might look something like

C:\java\bin\java.exe -Dhttp.proxyHost=http://localproxy -Dport=8331
1
13

You can use Microsoft's official Process Explorer. It can do exactly this and has many many more useful features.

1
  • 2
    One very useful note, after starting Process Explorer for the first time, right-click the table header ("Process" | "CPU" | "Private Bytes" | etc.) and add the "Command Line" column for the info you want to see. Very, very helpful tool, allows you to see what scripts IT is running on your machine...
    – xmnboy
    Jan 6 '18 at 0:11
23

Wmic.exe will show you what you are looking for:

wmic path win32_process get name,commandline > commandline.txt

Java looks like:

"C:\Program Files\Java\jre6\bin\jqs.exe" -service -config "C:\Program Files\Java\jre6\lib\deploy\jqs\jqs.conf"

For all available attributes, try:

wmic path win32_process get /format:list
7
  • 1
    I am getting error "Invalid GET expression" for the comma put between name and commandline. Rest all is working like charm. Jan 7 '16 at 19:57
  • I'm guessing you're running this within a batch file? try escaping the comma like so: "wmic path win32_process get name^, commandline"
    – RobW
    Jan 8 '16 at 0:16
  • 1
    Ok - If you issue the 'all available attributes command' noted above, in powershell, you get expected results. On reading further, in power shell, the comma does indeed need to be escaped. However, you use the forward quote: ` to do so: wmic path win32_process get name`, commandline
    – RobW
    Jan 18 '16 at 18:06
  • 2
    If you're running the first command, remove the space after the comma so that it looks like this: wmic path win32_process get name,commandline > commandline.txt That will remove the "Invalid GET expression" error Mar 6 '17 at 19:18
  • 2
    +1 thank you! Process Explorer fails if the command line is too long, but this command works just fine!
    – user541686
    Jan 18 '19 at 10:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.