Skip navigation
Aaronius9er9er
Currently Being Moderated

Air executing JRE installer - works in Eclipse, not as exe

Jun 16, 2010 9:40 AM

Hi guys.  I'm making an AIR app that, in Windows, determines if the user has Java installed and, if not, installs it by executing the JRE "online" installer (jre-6u20-windows-i586-iftw-rv.exe - downloadable from here: http://www.java.com/en/download/manual.jsp).  Here's my code:

 

 

package
{
     import flash.desktop.NativeProcess;
     import flash.desktop.NativeProcessStartupInfo;
     import flash.events.Event;
     import flash.events.IOErrorEvent;
     import flash.events.NativeProcessExitEvent;
     import flash.events.ProgressEvent;
     import flash.filesystem.File;
     
     import mx.controls.Alert;

     public class JavaUpgrade
     {
          protected var nativeProcess:NativeProcess;
          
          public function upgrade(installerPath:String):void
          {
               var info:NativeProcessStartupInfo = new NativeProcessStartupInfo();
               info.executable = File.applicationDirectory.resolvePath(installerPath);
               Alert.show('upgrade called: ' + info.executable.nativePath);
               info.workingDirectory = File.applicationDirectory;
               
               nativeProcess = new NativeProcess();
               addListeners(nativeProcess);
               nativeProcess.start(info);
          }
          
          protected function addListeners(nativeProcess:NativeProcess):void
          {
               if (nativeProcess)
               {
                    nativeProcess.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, outputDataHandler);
                    nativeProcess.addEventListener(ProgressEvent.STANDARD_ERROR_DATA, errorHandler);
                    nativeProcess.addEventListener(IOErrorEvent.STANDARD_INPUT_IO_ERROR, errorHandler);
                    nativeProcess.addEventListener(IOErrorEvent.STANDARD_OUTPUT_IO_ERROR, errorHandler);
                    nativeProcess.addEventListener(NativeProcessExitEvent.EXIT, exitHandler);
               }
          }
          
          protected function outputDataHandler(event:ProgressEvent):void
          {
               var output:String = nativeProcess.standardOutput.readUTFBytes(
                         nativeProcess.standardOutput.bytesAvailable);
               Alert.show(output);
          }
          
          protected function errorHandler(event:Event):void
          {
               Alert.show(event.toString());
          }
          
          protected function exitHandler(event:NativeProcessExitEvent):void
          {
               Alert.show(event.toString());
          }
     }
}

 

 

 

My code works exactly as expected when I'm debugging the app from Eclipse, but when I create a native installer, install the air app, and then run it, the JRE installer never appears.  I do get the alert that says, "upgrade called: C:\Program Files\JavaInstaller\jre-6u20-windows-i586-iftw-rv.exe" and that exe does exist at that location but it just never shows up.  Nor does any additional process show up in my task manager.  Ideas?  It's baffling.

  • Currently Being Moderated
    Community Member
    Jun 16, 2010 11:29 AM

    Actually - that is a great trick to know. There have been other requests by folks to allow some kind of auto-elevation of privs on windows when launching something with NativeProcess - but this is a great workaround.

     

    Thanks,

     

    Chris Thilgen

    AIR Engineering

    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points