interactive user name from within service

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.GetCurrent().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
 
Hi
You need to use the LoginUser API function that reside into the DLL
advapi32.dll
Here is a snippet of what you should have into your code
private System.ComponentModel.Container components = null;
[DllImport("advapi32.dll",EntryPoint = "LogonUser")]
private static extern bool LogonUser(
string lpszUsername,
string lpszDomain,
string lpszPassword,
int dwLogonType,
int dwLogonProvider,
ref IntPtr phToken);
there are many other functions that can help into that dll , you might need
to read about advapi32.dll to know more about that
hope that helps
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC
 
I thought "LogonUser" was used to impersonate another user. That isn't what I want to do. I want to know who the currently logged on user is.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top