如何获得当前登录的用户名和账户类型(管理员,非管理员),当应用程序被运行方式目前存在的用户 [英] How to get Currently Logged on User Name and Account Type(admin,nonadmin) When the application is Run As differnet User

查看:220
本文介绍了如何获得当前登录的用户名和账户类型(管理员,非管理员),当应用程序被运行方式目前存在的用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C#如何获得当前登录的Windows用户,如果应用程序是由不同的充用户使用为?

In C# How to get the currently logged on windows user if the application is executed by differnt user using Run as?

WindowsIdentity.GetCurrent(); 总是给人运行用户或模拟用户。我只是想在Windows登录用户名和用户帐户类型。

WindowsIdentity.GetCurrent(); always gives the Run as user or impersonated user. I just want the windows logged on user name and user account type.

推荐答案

尝试使用WMI来获得登录用户的会话: 从Win32_LogonSession *如果LogonType = 2

Try to use WMI to get logon user sessions: "Select * from Win32_LogonSession Where LogonType = 2"

这篇关于如何获得当前登录的用户名和账户类型(管理员,非管理员),当应用程序被运行方式目前存在的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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