Warm tip: This article is reproduced from serverfault.com, please click

其他-如何在PowerShell或C#中获取进程的命令行信息

(其他 - How to get Command Line info for a process in PowerShell or C#)

发布于 2013-07-10 05:58:31

例如:如果我跑步notepad.exe c:\autoexec.bat

我怎样才能c:\autoexec.batGet-Process notepadPowerShell中?

或者我怎样才能c:\autoexec.batProcess.GetProcessesByName("notepad");C#中?

Questioner
victorwoo
Viewed
11
Ansgar Wiechers 2017-01-31 17:18:58

在PowerShell中,你可以通过WMI获取进程的命令行:

$process = "notepad.exe"
Get-WmiObject Win32_Process -Filter "name = '$process'" | Select-Object CommandLine

请注意,你需要管理员权限才能访问有关在另一个用户的上下文中运行的进程的信息。作为普通用户,只有在你自己的上下文中运行的进程才对你可见。