I have a C++ program that runs as a service on a 64-bit Windows Server 2008 machine. This program attempts to start a batch file using the following command:
system(C:\pathtofile\file.bat)
In 32-bit Windows Server 2003 this worked fine (the batch file was executed), but on Windows Server 2008 the batch file is not executed and I get a return value of 0xC0000142 (I had the batch file write some text to a file as a test to see if it executed). I actually get that same return value even if I try to execute something that doesn't exist.
I read about Session 0 isolation in Windows Server 2008, so I used psexec to start a command prompt in Session 0 as the same domain user who is listed as the "Log On As" user for the service:
psexec -i 0 -u DOMAIN\serviceuser -p passwd cmd.exe
I was then able to successfully execute the batch file from the command prompt.
The domain user who is listed as the Log On As user for the service is in the Administrators group. Also if I start the C++ app manually (not as a service), it will start the batch file.
So is there something about Session 0 isolation that makes the system() call not work when the running as a service? Or some other explanation as to the change in behavior? I know that system() is not necessarily the best way to do this anyway, but I'm looking for the actual reason that this no longer works.