I am creating a library to work with windows services (poll their status, start them, check their cpu usage, etc). I am writing unit tests for this library. I need to change the user that is used by the test runs so that they have permision to perform some actions (start a service).
How can I change the identity the tests run under?
Thanks,
There isn’t a test specific solution to this. The short answer is: Impersonate the user you need using LogonUser(). The long answer is much longer, because LogonUser() is a Win32 call.
Take a look at this blog that’s trying to solve your problem.
I liked this codeproject implementation for calling LogonUser better. There’s actually many codeproject examples of LogonUser() if you search around a little.