简体   繁体   English

如何获取在Windows命令行上运行进程的用户帐户的名称?

[英]How to get name of user account running a process on Windows command line?

I parse the output of wmic to get pid (process identifier), command line, etc. of a running process. 我解析wmic的输出以获取正在运行的进程的pid(进程标识符),命令行等。 Unfortunately user name (user executing this process) is missing from wmic output. 不幸的是, wmic输出中缺少用户名(执行此过程的用户)。

Is there a method to get the name of the user account? 有没有获取用户帐户名称的方法?

Example wmic command: wmic命令示例:

wmic process where caption="explorer.exe"

Output: 输出:

Caption       CommandLine              CreationClassName  CreationDate    ...
explorer.exe  C:\Windows\Explorer.EXE  Win32_Process      20180214220330. ...

One possibility is using the command TASKLIST : 一种可能性是使用命令TASKLIST

tasklist /V /FI "IMAGENAME eq explorer.exe"

Run in a command prompt window tasklist /? 在命令提示符窗口中运行tasklist /? for help on this command which explains the used options. 有关此命令的帮助,该命令说明了使用的选项。

The same command line for usage in a batch file with full qualified file name: 在具有完整限定文件名的批处理文件中使用相同的命令行:

%SystemRoot%\System32\tasklist.exe /V /FI "IMAGENAME eq explorer.exe"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM