C#.NET入门使用Windows服务机器的用户名 [英] C#.NET Getting User Name of machine using Windows Service
问题描述
我有困难越来越登录到使用Windows服务的计算机的人的用户名。
I am having difficulty getting the User Name of a person logged into a machine using a windows service.
在同时使用System.Environment.UserName或WindowsIdentity.GetCurrent ().UserName我得到NTAUTHORITY\SYSTEM但是当这个应用程序被推我需要能够映射到登录到系统的人的用户名。操作系统这将被用于将Windows XP中。
When using both System.Environment.UserName or WindowsIdentity.GetCurrent().UserName I get NTAUTHORITY\SYSTEM but when this application gets pushed I need to be able to map to the UserID of the person logged in to the system. The operating system this will be used on will be Windows XP.
任何帮助将是非常赞赏。
Any help would be very appreciated.
推荐答案
有关XP只是,这样的建议应适用:的获取窗口站为每个进程,用户或会话的非交互式用户?
For XP only, this advice should apply: Get Window Station for a non-interactive user per process, user or session?
- 呼叫
OpenWindowStation
来得到一个处理winsta0 - 呼叫
GetUserObjectInformation
来找出谁拥有winsta0
- Call
OpenWindowStation
to get a handle to "winsta0" - Call
GetUserObjectInformation
to find out who owns winsta0
然而,这种做法将在升级打破你应用到Vista,Windows 7或以上,其中服务在交互式登录不同的会话中运行。你需要呼叫的终端服务API来获取登录的用户列表,并挑选您的互动之一。
However, this approach will break when you upgrade your app to Vista, Windows 7 or above, where services run in a different session from interactive logons. You'll need to call the terminal services API to get a list of logged on users, and pick your 'interactive' one.
这篇关于C#.NET入门使用Windows服务机器的用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!