Obtain the command line from a running process fro

2019-06-01 05:52发布

问题:

I wanted to determine the command-line arguments of a running process at the Command Prompt (cmd.exe).

E.g., if I started my abc.exe program as follows:

abc -d 

I want to determine the whole command line later. The TASKLIST utility does not provide this info, because it just reports the exe name and not the arguments with which the process was started.

回答1:

Here is a GUI-based method (Tested on Windows 7 - YMMV). I don't know of an easy method to get this data from the command-line.

  1. Open the Task Manager (CTRL+SHIFT+ESC), and go to the Processes tab.
  2. From the View menu -> Select Columns...
  3. Scroll to the very bottom and select "Command Line"
  4. In the newly-shown "Command Line" column, you can see the entire command that started the process, including any command-line parameters

Command-line method:

  1. Start a PowerShell with administrator priviledges
  2. Use the Get-WmiObject to list processes and filter the process name above. Add/remove fields through the select statement below - example:

    Get-WmiObject win32_process -Filter "name like '%notepad.exe'"|select CreationDate,ProcessId,CommandLine|ft -AutoSize
    

Note: The process name "notepad.exe" is used for this example, substitute the name for your specific scenario.



回答2:

the method from mellanmokb works acutally, but i think the question whould be? can i see in in code maybe, if that is the case, are you using C# o VB?.

If the case is C# you can see it in msdn library

There you can see that the arguments arrives at the Main(string[] args), and this is a string that you can read as argument = args[i] with i the number of the argument you want

for example if you call args[2] on the commandline was text.exe test here there

args[2] will be here.

remmember that args[i] is a string always.

hope this helped