如何获取进程所有者的用户名? [英] How do you get the UserName of the owner of a process?

查看:30
本文介绍了如何获取进程所有者的用户名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取当前用户 (Environment.UserName) 当前拥有的进程列表.不幸的是,Process 类无法获取拥有进程的用户的 UserName.

I'm trying to get a list of processes currently owned by the current user (Environment.UserName). Unfortunately, the Process class doesn't have any way of getting the UserName of the user owning a process.

如何使用 Process 类获取作为进程所有者的用户的用户名,以便我可以将其与 Environment.UserName 进行比较?

How do you get the UserName of the user which is the owner of a process using the Process class so I can compare it to Environment.UserName?

如果您的解决方案需要 pinvoke,请提供代码示例.

If your solution requires a pinvoke, please provide a code example.

推荐答案

CodeProject 文章 How通过 Warlib 获取进程所有者 ID 和当前用户 SIDa> 描述了如何使用 WMI 和通过 PInvoke 使用 Win32 API 来执行此操作.

The CodeProject article How To Get Process Owner ID and Current User SID by Warlib describes how to do this using both WMI and using the Win32 API via PInvoke.

WMI 代码更简单,但执行速度较慢.您的问题并未表明哪种更适合您的情况.

The WMI code is much simpler but is slower to execute. Your question doesn't indicate which would be more appropriate for your scenario.

这篇关于如何获取进程所有者的用户名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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