Windows Service

G

Guest

Hi...

In my service I need to determine the user that is Logged on.
I'm using

WindowsPrincipal wp = new WindowsPrincipal(WindowsIdentity.GetCurrent())
string name=wp.Identity.Name

but it returns NT ACCOUNT\SYSTEM instead of the actual user name.

I know why its doing this just don't know how to stop it from doing this

does anyone know a way to get the username.
 
N

Nicholas Paldino [.NET/C# MVP]

Rodney,

The reason it is doing this is because the service runs under a user
account that is configured for the service. In this case, the value being
returned from WindowsIdentity.GetCurrent is correct. You can't guarantee
that there at any point there is only one person logged into the machine, or
any, for that matter.

In order to get around this, you have two choices. The first is to have
this be an application that starts up when the user logs in. In this case,
it would seem appropriate, because your operations are tied into a user
being logged in, not to the machine being on (which is what a service is
more suited for).

The second option is to have your server take requests from an app that
is run when the user logs on. The app would send messages to your service,
along with the identity of the person running the app.

Hope this helps.
 

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

Top