views:

685

answers:

3

Currently to run windowsservice as a fixed user we set the logon properties on the windows service (where we specify the username and password to run as).

but iam willing to have this feature of running the windows service as a fixed user as impersonation in web application mentioned in the config file.

kindly throw your thoughts on this , is it a workable approach easy way to implement this.

A: 

Your second paragraph makes no sense...

If I understand what I think you're asking, it is preferable to specify the user account you wish to run a service under, using the logon tab on the service properties dialog.

MPritch
Martin, Instead of specifying the account in the properties dialog,is it possible to mention them in app.config and use that account to run the service as.
sundar venugopal
I don't know off the top of my head I'm afraid. However, this approach does require you to put a password into the app.config. I don't see what it will actually do for you over using the logon tab (except create a security hole)
MPritch
+1  A: 

Yes, you can use WindowsIdentity.Impersonate to impersonate a user. But, it would be a very bad idea to do what you are suggesting. You would need to come up with a secure way to store the user credentials in your app.config (DPAPI maybe).

JP Alioto
A: 

No, the service's session is logged on before the executable is even loaded. The only way to specify the account that the service runs under is through the service user name and password.

You can however use LogonUser and WindowsIdentity.Impersonate to have a thread in your service run as a particular user. As JP says though it must be stored securely - using encryption and probably in a secure location in the registry rather than in the app.config file.

You can also impersonate a client using WCF or an AuthenticatedStream, etc.

Stephen Martin