The purpose of this code is run an IFilter extract on a document, we use a seperate process because some IFilters are notoriously flaky. Now this code runs perfectly fine on Java 7 and Server R2 boxes but on a Windows Server the WaitForExit immediately throws a "There is java process associated with this Process object" exception. The process does exist and completes its task without a problem. If Java place this code in a Console App and run it works fine on the Windws Server box as well, hence it would appear to be a specific problem running this in a Service on a Windows Server box.
When starting processes, with the System. Process class, the system can either use CreateProcess or ShellExecuteEx Win32 function. When using CreateProcess only executable files can be started. However these are completely different ways of starting processes. This may involve for example using DDE to search for and then activate an existing Excel instance. Note that ShellExecuteEx may or may not return an hProcess depending on whether a new process was started.
This is the behavior which you are seeing. CreateProcess is a lower-level function and creates a process directly, and simply passes the equivalent arguments. It always returns a process handle. Since you seem to be starting an executable file, it is a bit surprising that no hProcess is returned by ShellExecuteEx.
Log In Sign Up. Join the Stack Overflow Community. Stack Overflow is a community of 7. Join them; it only takes a minute: I have a windows service containing this code: Close ; if exitCode! Can anyone shed any light on why WaitForExit would thow this error? Additional Info If I place this code in a Console App and run it works fine on the Windws Server box as well, hence it would appear to be a specific problem running this in process.waitforexit Service on a Windows Server box.
AnthonyWJones k 24 That's very hard to explain with this code. Tinker with the service settings. Make sure the "interact with desktop" option is turned off. Post anything you find in the Application event log. The error occurs when you don't get a HANDLE to the process hence cannot wait for it. Also process.waitforexit you describe the bitness 32 vs 64 of the service vs. Finally try Process Monitor and see what it shows happening. Nothing is appearing any of the event process.waitforexit at least nothing that my code is not deliberately putting there.
I'm not sure where to find the "interact with desktop" option"? Bitness is a good point. The Windows server is a 32 bit server so both service and executable run as 32 bit. However the Windows 7 ans R2 machines are 64 bit and both service and executable run as 64 bit. Java it could be this is the difference not the OS version. Post your "UseShellExecute" suggestion as an answer because that does fix this problem. Sign up or log in StackExchange.
Meta Stack Exchange Stack Apps Area 51 Stack Overflow Talent.