Q:

Run external binary as a different user

I'm testing a small utility program. It behaves differently depending on whether it's being run with administrative rights or not. Therefore, my test framework needs to invoke the program both with and without admin rights, to check that it behaves appropriately.
The test framework is written in C#. Our CI server will run the test at midnight each day, so it's no good popping up access confirmations or similar; there won't be a human being there to press the button or type in credentials. I would prefer to avoid having to store the administrator's password if possible.
Where do I start with this? It looks like ProcessStartInfo can take a username, domain and password - but that would require the admin password to be compiled into the test framework. (Like that will work on more than one PC!) I've also seen answers that say something about WindowsIdentity and impersonation - but that seems to be to change the user ID of the current process, not the external process that I'm trying to invoke.

A:

What about this:

Your test framework expects the username/password for the admin rights via command line parameters
your CI server calls this with the parameters - at least there you have to store the password. Any non-interactive solution demands the storage of the password somewhere
Your test framework will spawn the application then with ProcessStartInfo.

At least the password is not stored in code anymore, which makes it better to manage and not to leak it beyond Admin´s scope ;)
BR Florian

