Call netsh from Adobe Air - actionscript-3

Hi I'm trying to set up a Wifi Hotspot from Adobe Air with
var netsh:NativeProcessStartupInfo = new NativeProcessStartupInfo();
var file:File = File.applicationDirectory.resolvePath("C:/Windows/System32/netsh.exe");
netsh.executable = file;
var processArgs:Vector.<String> = new Vector.<String>();
processArgs.push("wlan set hostednetwork mode='allow' ssid='tests' key='tests123'");
netsh.arguments = processArgs;
process = new NativeProcess();
process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
process.start(netsh);
The application is starting, but doesn't like the arguments - throwing the error:
The following command was not found: "wlan set hostednetwork mode='allow' ssid='tests' key='tests123'".
Is there a better way of doing this? Is it even possible!?
I have tried without quotes - this was just the latest attempt

This works
var netsh:NativeProcessStartupInfo = new NativeProcessStartupInfo();
var file:File = File.applicationDirectory.resolvePath("C:\\Windows\\System32\\cmd.exe");
netsh.executable = file;
var processArgs:Vector.<String> = new Vector.<String>();
processArgs.push("/c netsh wlan set hostednetwork mode=allow ssid=test key=test1234");
netsh.arguments = processArgs;
process = new NativeProcess();
process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
process.start(netsh);

Related

Launch Inno Setup Update from within AIR

I am using Inno Setup to create my installer for a desktop AIR app. I have my desktop app check my database for an app version number to let the user know if there is an update ready to install. I would like to have a pretty seamless update process for the user, so if they want to update, I would like for AIR to download the EXE and then run it.
1.) How do you download big files like an EXE from the web in AIR and do you need to place it someplace specific?
2.) Once the file is downloaded, how do I get AIR to execute the EXE?
Thanks!
public static function download(sourceURL:String, destinationPath:String, complete:Function = null, progress:Function = null, error:Function = null):void
{
var urlReq:URLRequest = new URLRequest(sourceURL);
var urlStream:URLStream = new URLStream();
var fileData:ByteArray = new ByteArray();
if(progress != null) urlStream.addEventListener(ProgressEvent.PROGRESS, progress);
if(error != null) urlStream.addEventListener(IOErrorEvent.IO_ERROR, error);
urlStream.addEventListener(Event.COMPLETE, loaded);
urlStream.load(urlReq);
function loaded(event:*):void
{
urlStream.readBytes(fileData, 0, urlStream.bytesAvailable);
writeFile();
}
function writeFile():void
{
var file:File = new File(destinationPath + sourceURL.slice(sourceURL.lastIndexOf("/"), sourceURL.length));
var fileStream:FileStream = new FileStream();
fileStream.open(file, FileMode.WRITE);
fileStream.writeBytes(fileData, 0, fileData.length);
fileStream.close();
if(complete != null) complete();
}
}
var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
nativeProcessStartupInfo.executable = file;
process = new NativeProcess();
process.closeInput();
process.start(nativeProcessStartupInfo);

Sending script to php file with URLLoader returns 0 when I try to GET it

I have a game, I want to write score in my database when the game is over. This is the urlloader function:
public function gameFinished(){
var urlLoader:URLLoader = new URLLoader();
var req:URLRequest = new URLRequest("/../../sendScoreUnit4.php");
var requestVars:URLVariables = new URLVariables();
requestVars.score = total_score_hard;
req.data = requestVars.score;
req.method = URLRequestMethod.POST;
urlLoader.load(req);
}
My sendScoreUnit4.php file tries to get the score like so :
$score = (int)$_GET['score'];
but when I echo it I get 0 every time.
Any help would be appreciated.

Load external swf into bytearray with adobe flash

How can I load external swf into bytearray with adobe flash AS3..
Here is my code..
var my_url1:URLRequest = new URLRequest("SWF/Lesson1.swf");
my_url1.method = URLRequestMethod.GET;
my_url1.contentType = "application/x-shockwave-flash";
var urlloader:URLLoader = new URLLoader(my_url1);
var myByteArray:ByteArray = new ByteArray();
urlloader.data = myByteArray;
It not works well. But it isn't give any error. How can I fix this problem?
You should listen for COMPLETE event and set the data format to BINARY:
var my_url1:URLRequest = new URLRequest("SWF/Lesson1.swf");
var urlloader:URLLoader = new URLLoader(my_url1);
urlloader.dataFormat = URLLoaderDataFormat.BINARY;
urlloader.addEventListener(Event.COMPLETE, function(event:Event):void
{
var myByteArray:ByteArray = URLLoader(event.target).data as ByteArray;
trace(myByteArray.length);
});

LocalConnection var into URLRequest

i use LocalConnection between two swf in the same page.
What i'm trying to do is to use a String sent from one swf to the other, as variable into my URLRequest...
So i can trace "myVar" into the function chemin, but i didn't find how to use it into URLRequest
thank's for your help
swf that receive the var :
var lc:LocalConnection=new LocalConnection();
lc.client=this;
lc.connect("callBig");
function chemin(myVar:String){
trace(myVar)
}
var chargementXML:URLLoader = new URLLoader();
var fichier:URLRequest = new URLRequest(myVar);
Some references to help you out.
URLRequest.data: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLRequest.html?filter_flex=4.1&filter_flashplayer=10.2&filter_air=2.6#data
URLVariables: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLVariables.html
So, if you want to pass some variables in your request, you do the following:
Create new URLVariables() object
Assign it's reference to URLRequest.data field.
var fichier:URLRequest = new URLRequest();
var urlVars:URLVariables = new URLVariables();
urlVars["myVarName"] = myVar;
fichier.data = urlVars;
This way your server side app will recieve a variable myVarName with value of myVar.
var lc:LocalConnection=new LocalConnection();
lc.client=this;
lc.connect("callBig");
var receivedVar:String = "";
// somewhere else
function chemin(myVar:String){
receivedVar = myVar;
}
// later
var chargementXML:URLLoader = new URLLoader();
var vars:URLVariables = new URLVariables();
vars.myVar = receivedVar;
chargementXML.data = vars;
var fichier:URLRequest = new URLRequest(myVar);

execute remote SWF in AIR Security Sandbox

I try to download an external SWF and run it within the AIR security sandbox.
this is the code of the AIR application:
public class Downloader extends Sprite
{
private static const REMOTE_FILE:URLRequest = new URLRequest("http://myserver.com/downloadable.swf");
private var _main:NativeWindow;
public function Downloader()
{
var loader:URLLoader = new URLLoader(REMOTE_FILE);
loader.dataFormat = URLLoaderDataFormat.BINARY;
loader.addEventListener(Event.COMPLETE, downloadComplete);
}
private function downloadComplete(e:Event):void{
var ba:ByteArray = e.target.data;
var stream:FileStream = new FileStream();
var file:File = File.applicationStorageDirectory.resolvePath("downloadable.swf");
stream.open(file, FileMode.WRITE);
stream.writeBytes(ba);
stream.close();
loadAndRunSwf();
}
private function loadAndRunSwf(){
this._main = new NativeWindow();
this._main.width = 1024;
this._main.height = 768;
////obsolete?
//var context:LoaderContext = new LoaderContext();
//context.allowLoadBytesCodeExecution = true;
//context.applicationDomain = ApplicationDomain.currentDomain;
var file:File = File.applicationStorageDirectory.resolvePath("downloadable.swf");
var loader:Loader = new Loader();
loader.load(new URLRequest(file.url)/*,context*/);
this._main.stage.addChild(loader);
this._main.activate();
}
}
Code of the downloadable.swf:
public class Downloadable extends Sprite
{
private var _btn:Button = new Button();
private var _baseFolder:File = new File("app-storage:/");
public function downloadable_test()
{
this.addChild(_btn);
_btn.label = "access Harddisk";
...
}
}
so now, If I run Downloader, it will download the swf and try to run it, but i'll get an exception in Downloadable on the line
private var _baseFolder:File = new File("app-storage:/");
the error:
SecurityError: file
at runtime::SecurityManager$/checkPrivilegeForCaller()
So - what Do I need to do to prevent such security errors? I want my remote SWF to be treated as native code running in the same security sandbox as the AIR code.
I'm not sure about Android, but for the regular web player you would need to specify SecurityDomain.currentDomain for the securityDomain of the Loader's context for the loaded code to be considered equal to the loader in terms of permissions. Also note that for reasons impossible to explain, if you use SecurityDomain when loading from the file system on PC Flash Player will complain.
However complicated, the Flash Player security is often a security by obscurity... So, if it doesn't work the way you coded it, try Loader.loadBytes() "workaround".
function loadAndRunSwf()
{
var context:LoaderContext=new LoaderContext(false);
context.allowCodeImport=true;
var ba:ByteArray=new ByteArray();
var file:File = File.applicationStorageDirectory.resolvePath("downloadable.swf");
var fileStream:FileStream=new FileStream();
var loader:Loader = new Loader();
fileStream.open(file,"read");
fileStream.readBytes(ba);
ba.position=0;
loader.loadBytes(ba,context);
this._main = new NativeWindow();
this._main.width = 1024;
this._main.height = 768;
this._main.stage.addChild(loader);
this._main.activate();
}