I am trying to have a service running on a Windows Server 2008 R2 be able to execute dcpromo in order to join and remove AD. In Server 2003, I was able to simply use Process.Start() in C# and provide the path to dcpromo and the path to the answer file provided by a user.
However, in Server 2008, this returns FileNotFoundException. I have verified the path to dcpromo, and have even tried running other executables in the System32 folder like ipconfig and whoami which execute just fine.
The service is running as Local System account and the only way I have found to get it to work is save the command to a batch file and impersonate an Administrator to execute the batch file. But this has it's own issue like requiring an Administrator's password.
According to the permissions on the dcpromo.exe, the SYSTEM account has read/execute permissions, and I have tried giving full permissions and changed the owner to SYSTEM, but none of this helped. The same code works if ran by a user as a regular application (i.e. not a service).
Any idea how to grant SYSTEM account permissions to execute dcpromo while running under a service in Server 2008 R2?