By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,665 Members | 1,258 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,665 IT Pros & Developers. It's quick & easy.

currently logged on username from within service

P: n/a
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
Nov 16 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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]
- mv*@spam.guard.caspershouse.com

"ChrisB4745" <Ch********@discussions.microsoft.com> wrote in message
news:95**********************************@microsof t.com...
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

Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.