Search code examples
.netmstestintegration-testinguser-accountslocalsystem

Is it possible to run tests as the `Local System` user?


I'm writing an integration test that requires the method to be run in the Local System security context to achieve the desired behavior. I couldn't achieve this yet. What should I do?

I'm using C#, VS 2010, MsTest and the target project is a Windows Service app.


Solution

  • I see two options.

    You can write a Windows service.

    This is not as much work as it sounds. You can have that listen for commands, using e.g. WCF. If you set the privilege of that service to Local System you can have that service run your unit tests.

    You can use scheduled tasks.

    If you want your tests to run periodically, you can use scheduled tasks to schedule the task with the Local System privileges.