简体   繁体   English

从其他用户会话获取当前登录的用户

[英]Getting the Current Logged On User from a different User Session

I'm running a .Net application as a service under a special application user. 我正在将.Net应用程序作为服务在特殊应用程序用户下运行。 From this service, i would like to get the User Name running the currently logged in session. 通过此服务,我想获得运行当前登录会话的用户名。

I tried getting the user name that owns the Explorer.exe process, but the restricted user does not have access to this as it throws an exception if i try and get the process handle. 我尝试获取拥有Explorer.exe进程的用户名,但受限用户无权访问此文件,因为如果我尝试获取进程句柄,它将引发异常。

What other options are available? 还有哪些其他选项?

Regards 问候

Tris 特里斯

Using System.Environment.UserName will get you what you need, as well as domain if you like etc. A very very useful class. 使用System.Environment.UserName可以为您提供所需的信息,如果需要还可以提供域等信息。这是一个非常有用的类。


EDIT: 编辑:

Alright then, try this? 好吧,尝试这个吗?

System.Security.Principal.WindowsIdentity user = System.Security.Principal.WindowsIdentity.GetCurrent();

string Name = user.Name;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM