Jun 16, 2010 9:40 AM
Air executing JRE installer - works in Eclipse, not as exe
-
Like (0)
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.
I think it has to do with user access control. When I attempt to run the JRE installer from windows explorer, it requires permission. So then I thought, well what if I run the Air app's exe with admin privileges. Sure enough, the JRE installer showed up. So I'm okay with having the AIR app attempt to run the installer and having the user be prompted for permission, but how do I even do that?
Message was edited by: Aaronius9er9er
I found that if I execute the java installer using cmd that it will force windows to open the privileges prompt. It seems to do the trick. Thanks for letting me talk to myself.
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
Thanks for the response. It's a nice workaround but I'm wondering if this shouldn't be taken care of natively by Air. Or, Windows...I don't know where the deficiency is. I just find it awkward that when attempting to execute a process that requires elevated privileges it doesn't show up, doesn't display an error, nothing. I would assume if cmd can force the prompt then Air could do likewise. If you see this as being a possibility, I'd be glad to enter a feature/bug ticket if you would point me in the right direction.
Copyright © 2011 Adobe Systems Incorporated. All rights reserved.
Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy (updated 07-14-2009).