views:

1398

answers:

3

Hi,

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);
        }
+2  A: 

Hello,

(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

kaboom
+1  A: 

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

Markus Lausberg
A: 

Gr8 answer i am sharing your opinion on all sites. Thank a lot.

sushil khekare