views:

208

answers:

2

I am working on a project that requires sandboxing an application. I am able to create a windows user, create a directory, fill the directory with an application, and run the application as a user. This works completely fine running as a console application, but when I install it as a service, I get this exception:

System.ComponentModel.Win32Exception: Access is denied
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()

The code that throws this exception is:

_process = new Process
     {
     StartInfo =
        {
            Arguments = "",
            CreateNoWindow = true,
            ErrorDialog = false,
            FileName = instanceDirectory + "program.exe",
            WorkingDirectory = instanceDirectory,
            UseShellExecute = false,


            UserName = GetUserNameForInstance(_id),
            Password = GetPasswordForInstance(_id),
            Domain = ""
        },
    EnableRaisingEvents = true
    };

_process.Exited += ProcessExited;
_process.Start();

Again, this is only thrown when running as a Windows Service. The service is running under LOCAL SYSTEM according the the Services panel in Windows.

Any Ideas?

+1  A: 

Does the account have the premissions to the resources you are using? Does it have the ability to read and write to the directory?

In these types of situations 99% of the time it is a premission issue.

David Basarab
The user has permission for those resources, and the process starts correctly when the application starting it is running from the console. My only guess is its an issue with actually starting a process as a different user from a service. The only significant differences from running as a service and a console is the service has LOCAL SYSTEM permissions while the console runs as the current user. Is there any sort of flag I should be starting the service with?
Mike Ortman
A: 

You might be better off running the service as a domain account which has the necessary permissions for IO operations (including ACL permissions).

In the below example the "Alterter" service is set to run as the local service account. In your case I'd suggest running the service as DOMAIN\UserAccount.

alt text

Kane