如何在 PowerShell 或 C# 中获取进程的命令行信息 [英] How to get Command Line info for a process in PowerShell or C#

查看:88
本文介绍了如何在 PowerShell 或 C# 中获取进程的命令行信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如:如果我运行 notepad.exe c:autoexec.bat

如何在 PowerShell 的 Get-Process notepad 中获取 c:autoexec.bat?

How can I get c:autoexec.bat in Get-Process notepad in PowerShell?

或者如何在 C# 中的 Process.GetProcessesByName("notepad"); 中获取 c:autoexec.bat ?

Or how can I get c:autoexec.bat in Process.GetProcessesByName("notepad"); in C#?

推荐答案

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

In PowerShell you can get the command line of a process via WMI:

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

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

Note that you need admin privileges to be able to access that information about processes running in the context of another user. As a normal user it's only visible to you for processes running in your own context.

这篇关于如何在 PowerShell 或 C# 中获取进程的命令行信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆