Question

i want to execute a setup.exe installer which installes a software on vista with java 1.6.

The user is not an administrator. When i try to start the process i get the error message:

CreateProcess error=740

which indicates, that the user has not enough rights for starting the process.

Can i submit a flag or an option to indicate, the the process should execute with administrator rights? Vista itself does have this functionality inside the menu toolbar. Can i use this function in Java.

I call the following code

        Runtime rt = Runtime.getRuntime();
        Process process;
        try {
            String fileToExecute = new File(mFolder, mSetupFiles[0]).getCanonicalPath();

            if (logger.isDebugEnabled()) {
                logger.debug("Execute runtime process");
            }
            process = rt.exec(fileToExecute, null, mFolder);

            process.getErrorStream().close();
            process.getInputStream().close();
            process.getOutputStream().close();

            if (logger.isDebugEnabled()) {
                logger.debug("Wait until process is finished");
            }
            process.waitFor();
        } catch (IOException e) {
            throw new StartException(e);
        } catch (InterruptedException e) {
            throw new StartException(e);
        }
Was it helpful?

Solution 2

After 2 days of testing i found the following solution.

The error comes up when the Vista UAC functionality is activated. UAC shows a question dialog everytime, when a process needs administrator rights.

Showing this dialog causes the issue.

Instead of using the old

process = rt.exec(fileToExecute, null, mFolder);

command, i am using now the new 1.5 ProcessBuilder command

EDIT:

To avoid the problem you have to open a command window which requests the permission. And than you have to call the external process.

ProcessBuilder builder = new ProcessBuilder(new String[] { "cmd.exe", "/C", fileToExecute });

Also described here Execute an external Program

OTHER TIPS

(I have not tried this), but it seems that you can do this using the "elevate" program from here

also read this for UAC overview

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top