如何使用c#获取当前登录的用户 [英] How to get the currently logged in users using c#
本文介绍了如何使用c#获取当前登录的用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我设法使用以下代码获取在服务器中注册的用户列表
I managed to get the list of users registered in the server using the following code
ManagementObjectSearcher srch = new ManagementObjectSearcher("root\\CIMV2","select * from win32_useraccount");
foreach(ManagementObject mObj in srch.Get())
{
textBox1.Text += mObj["name"]+Environment.NewLine;
}
我现在需要获取当前登录用户的进程ID
I need now to get the currently logged in users with their process id
推荐答案
Cassia就是你所需要的,我用它来做类似的项目,
下面是下载源码的链接以及如何使用它的信息。 br $> b $ b
http://code.google.com/p/cassia/ [ ^ ]
也可以参考 http://stackoverflow.com/questions/132620/how-do-you-retrieve-a-list-of-logged-in-connected-users-in-net [ ^ ]
Cassia is what you need, I used this for a similar project,
Below is the link to download the source as well as information on how to use it.
http://code.google.com/p/cassia/[^]
one can also refer to http://stackoverflow.com/questions/132620/how-do-you-retrieve-a-list-of-logged-in-connected-users-in-net[^]
您可以通过两种不同的方式实现这一目标/>
You can achieve this in two different ways
string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
or
userName = Environment.UserName;
在 MSDN system.security.principal.genericprincipal [ ^ ]& system.environment.username.aspx [ ^ ]
read more at MSDN system.security.principal.genericprincipal[^] & system.environment.username.aspx[^]
这篇关于如何使用c#获取当前登录的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文