Reputation: 15656
I currently convert an application to use CreateProcessW()
instead of Runtime.exec()
as I need the information it provides. However any call to CreateProcessW() fails with the error code 5 (ACCESS DENIED). I have been unable to find out why this happens as Runtime.exec() runs fine in the same case.
My error could be in one of the following code snippets, the method call and the jna interface.
public ProcessInfo createProcess(String dir, String name){
ProcessInfo pi = new ProcessInfo();
StartupInfo start = new StartupInfo();
mem.CreateProcessW(new WString(name),
null,
null,
null,
false,
0,
null,
new WString(dir),
start.getPointer(),
pi.getPointer());
return pi;
}
My definition of CreateProcessW
boolean CreateProcessW(WString apname,
char[] comline,
Pointer p,
Pointer p2,
boolean inheritHandles,
int createFlags,
String environment,
WString directory,
Pointer startinf,
Pointer processInfo);
Additional Info:
Example parameters used:
Also tested with different paths, so not a whitespace problem
Thanks
Update:
As it turns out the error was caused by my calling code switching around working dir and exe path after I checked them. Because of the resulting access denied I actually thought that it at least found the exe. I will add an IllegalArgumentException to take care of that problem.
Since I had the additional error with the exe being relative to the working dir I will accept that answer. Thanks to all for helping.
Upvotes: 2
Views: 4171
Reputation: 705
CreateProcessW's first parameter has to be either a full path or a path relative to the current directory. It can't be a path relative to the working directory parameter, which seems like what you're expecting it to do.
Try passing C:\Programme\Movie Maker\moviemk.exe
as the name parameter
Upvotes: 1
Reputation: 6358
What is the full path you are entering? Runtime.exec
might be quoting the argument internally, and you could be running into this situation:
http://support.microsoft.com/kb/179147
Maybe there is a prefix to the path that exists and is causing it to try to execute a folder or other file?
Try putting quotes around the entire path and see if that helps.
Upvotes: 0
Reputation: 221997
The first parameter lpApplicationName
of the CreateProcess function will be used as NULL
typically and the second parameter lpCommandLine
should contain the command line starting with the program name which you want to start.
Just fry to switch the first and the second parameters which you use currently by the CreateProcessW
call.
Upvotes: 1