Obtain the command line from a running process from the Command Prompt [closed]

笑着哭i 提交于 2019-12-08 12:13:29

问题


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



来源:https://stackoverflow.com/questions/7494073/obtain-the-command-line-from-a-running-process-from-the-command-prompt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!