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

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

问题描述

我试图让目前由当前用户拥有的进程列表(Environment.UserName <$ C C $>)。不幸的是,进程类没有任何办法得到一个拥有进程的用户的用户名。

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.

你如何这是一个过程使用进程所有者的用户的用户名类,所以我可以把它比作环境。用户名

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 ,请提供code的例子。

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

推荐答案

在$ C $的CProject文章如何通过 Warlib >描述了如何同时使用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 code就简单多了,但执行起来慢。你的问题并不表示这将是更适合您的方案。

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天全站免登陆