我如何从.NET Windows服务当前登录的用户名? [英] How do I get the currently-logged username from a Windows service in .NET?
问题描述
我有一个Windows服务,需要当前登录的用户名。我试图 System.Environment.UserName
,Windows标识和Windows形式的认证,但都返回的系统作为用户的我的服务正在运行系统特权。有没有一种方式来获得用户名当前登录不改变我的服务帐户类型?
I have a Windows service which need the currently logged username. I tried System.Environment.UserName
, Windows identity and Windows form authentication, but all are returning "System" as the user as my service is running in system privileged. Is there a way to get the currently logged in username without changing my service account type?
推荐答案
我用了一个 WMI 查询来获取这个(见<一href=\"http://stackoverflow.com/questions/5218778/how-do-i-get-the-currently-logged-username-from-a-windows-service-in-net/7186755#7186755\">Tapas's回答)。其他的一切都被退回服务的用户名。
I used a WMI query to get this (see also Tapas's answer). Everything else was returning the username of the service.
这篇关于我如何从.NET Windows服务当前登录的用户名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!