开发者

CreateProcessW fails (ACESS_DENIED)

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:

  • Runtime.exec() succeeds with the given Strings
  • The size of StartupInfo is set
  • Testenvironment used: WinXP SP3 and Netbeans 6.9.1

Example parameters used:

  • Name: moviemk.exe
  • Dir: C:\Programme\Movie Maker\

Also tested with different paths, so not a whitespace problem开发者_如何学JAVA

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.


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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜