2

I need to kick off a 3rd party java application from a c# .net application. Originally I wanted to do this from an asp.net site but after running into problems with permissions/privileges I moved onto attempting to do it from a windows service since it runs as the system user which I'd hoped would remove my problems. Oh yes and my problems are occuring when trying to run this on a windows 2008 server. All is good in my windows 7 development environment.

Naturally I have scoured these forums and others for answers and nothing I have found has helped so please entertain me.

I have the command I want to run in a batch file and am using the following code to start it.

ProcessStartInfo psi = new ProcessStartInfo(filePathToBatchFile);
        psi.Arguments = "arguments for batch file..."
        psi.UseShellExecute = false;
        psi.RedirectStandardOutput = true;
        psi.RedirectStandardError = true;
        psi.RedirectStandardInput = true;
        Process p = Process.Start(psi);

I'm running a batch file essentially because I wanted to make sure that something was happening. I have made sure that all the variables and file paths are correct and that the batch file is indeed running. I can get it to do other things like xcopy files around and I can run the command myself from the command line and it works fine. There are no exceptions being thrown and no output from the process. If I changed the paths (to the java binaries, the files that I'm passing to it etc.) to deliberately incorrect ones then it complains.

I have tried running this process as different users, namely the one I can use to log into the server and run the command manually. I have given the service access to the desktop from the services properties menu.

If anyone has any ideas about what is happening here, or even some tips on how I can go about diagnosing this it would be hugely appreciated.

Blorgbeard
  • 101,031
  • 48
  • 228
  • 272
rmsylvester
  • 81
  • 2
  • 4
  • Could you provide the output from RedirectStandardOutput and RedirectStandardError, please? We could "entertain" you everlasting without some facts about what was happened. Because it"s abnormal and all that was suggested http://stackoverflow.com/questions/361097/c-service-cannot-execute-batch-file should lead to normal execution. – apros Jan 28 '11 at 16:53
  • There is no output from RedirectStandardOutput or RedirectStandardError. – rmsylvester Jan 31 '11 at 14:44

1 Answers1

1

You have to create a manifest for your app or turn off UAC.

What is happening is that since it is not a signed executable the UAC is preventing your service from running/starting other apps. That's where the manifest comes in.... Look it up in the Windows SDK documentation (Applicaiton Manifest).

I have ran into issues like this before, and whats most annoying is that there are no errors: http://msdn.microsoft.com/en-us/library/bb756929.aspx and here: http://technet.microsoft.com/en-us/library/xc3tc5xx(VS.80).aspx (better description)

Tutorial on manifests: http://msdn.microsoft.com/en-us/library/bb756973.aspx (Very Good)

Windows App Permissions and UAC (Vista, 7, 2008/R2) http://msdn.microsoft.com/en-us/library/bb756996.aspx

bleepzter
  • 9,607
  • 11
  • 41
  • 64
  • Thanks for the links! Your help is much appreciated. Before I got round to reading them I ended up accidentally solving the problem. Instead of kicking off a Java app I found a Python script that did the same thing. It works fine, but I really don't see why calling the Python executable would make things any different. – rmsylvester Feb 07 '11 at 17:10