Connecting Tech Pros Worldwide Help | Site Map

currently logged on username from within service

ChrisB4745
Guest
 
Posts: n/a
#1: Nov 16 '05
I'm working on a system service application that is supposed to report various information about the computer it is running on back to a central server. One of the things I need to know is the username of the person who is currently logged on to the actual computer. I've tried using
Name = System.Security.Principal.WindowsIdentity.GetCurre nt().Name.ToString();
However, since the service is owned by "System" I get "NT_AUTHORITY\SYSTEM" as a result. So how do I get the username of the person who is logged on instead of the name of the owner of the current process?

Thanks for any help,
Chris
Nicholas Paldino [.NET/C# MVP]
Guest
 
Posts: n/a
#2: Nov 16 '05

re: currently logged on username from within service


Chris,

I think you might want to re-think what you are trying to do. It is
actually possible to have multiple logon sessions on the computer at the
same time (a process might run another process as a different user, causing
another logon session, for example).

In order to get the information about these logon sessions, your easiest
solution is to go through the System.Management namespace, querying for all
instances of the Win32_LogonSession WMI class. You can find an example here
(watch for line wrap):

http://groups.google.com/groups?hl=e....phx.gbl#link2

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com

"ChrisB4745" <ChrisB4745@discussions.microsoft.com> wrote in message
news:95BC865A-9105-4500-B323-13EE58D7620A@microsoft.com...[color=blue]
> I'm working on a system service application that is supposed to report[/color]
various information about the computer it is running on back to a central
server. One of the things I need to know is the username of the person who
is currently logged on to the actual computer. I've tried using[color=blue]
> Name =[/color]
System.Security.Principal.WindowsIdentity.GetCurre nt().Name.ToString();[color=blue]
> However, since the service is owned by "System" I get[/color]
"NT_AUTHORITY\SYSTEM" as a result. So how do I get the username of the
person who is logged on instead of the name of the owner of the current
process?[color=blue]
>
> Thanks for any help,
> Chris[/color]


Closed Thread