I need to impersonate the LogOn user account of a particular windows service.
I have been able to get the username using WMI (sadly the LogOn user identity doesn't seem to be exposed using any of the regular windows service related .NET classes). But, armed with only the username (which could be either a local or domain account) how do I get the token for that windows identity?
The LogonUser WinAPI call which can provide the token expects the password as an argument, which obviously is not available. User input is not an option.
Any insight will be appreciated.
Ended up doing the following:
Hope this is useful to anyone else who needs to impersonate the user account that a service is running under.