我如何从.NET Windows服务当前登录的用户名? [英] How do I get the currently-logged username from a Windows service in .NET?

查看:120
本文介绍了我如何从.NET Windows服务当前登录的用户名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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屋!

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