如何获得当前登录的用户名和账户类型(管理员,非管理员),当应用程序被运行方式目前存在的用户管理员、账户、如何获得、应用程序

2023-09-05 04:30:16 作者:爷、跪下唱征服℡

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"