У меня есть этот класс:
public class UserDomainWindows extends EventDispatcher
{
public static const EVENT_COMPLETE:String = "complete";
private var process:NativeProcess;
private var file:File;
public function UserDomainWindows()
{
}
public function get():void {
file = File.applicationStorageDirectory.resolvePath("_getuserdomain.cmd");
var fs:FileStream = new FileStream();
fs.open(file, FileMode.WRITE);
fs.writeUTFBytes("@echo off\r\n");
fs.writeUTFBytes("echo %username%\r\n");
fs.writeUTFBytes("echo %userdomain%");
fs.close();
getCurrentOSUser();
}
private function getCurrentOSUser():void
{
var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
nativeProcessStartupInfo.executable = file;
process = new NativeProcess();
process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
process.start(nativeProcessStartupInfo);
}
private function onOutputData(event:ProgressEvent):void
{
var output:String = process.standardOutput.readUTFBytes(process.standardOutput.bytesAvailable);
file.deleteFile();
var sz:Array = output.split("\r\n");
this.dispatchEvent(new UserDomainWindowsEvent("complete", sz[0], sz[1]));
}
}
и этот класс событий:
public class UserDomainWindowsEvent extends Event
{
public var username:String;
public var userdomain:String;
public function UserDomainWindowsEvent(type:String, username:String, userdomain:String, bubbles:Boolean=false, cancelable:Boolean=false)
{
super(type, bubbles, cancelable);
this.userdomain = userdomain;
this.username = username;
}
public override function clone():Event
{
return new UserDomainWindowsEvent(type, this.username, this.userdomain, bubbles, cancelable);
}
public override function toString():String
{
return formatToString("UserDomainWindowsEvent", "type", "username", "userdomain", "bubbles", "cancelable", "eventPhase");
}
}
пример:
public function Main():void
{
var ud:UserDomainWindows = new UserDomainWindows();
ud.addEventListener(UserDomainWindows.EVENT_COMPLETE, onGetUserDomain);
ud.get();
}
private function onGetUserDomain(e:UserDomainWindowsEvent):void {
trace("username: " + e.username);
trace("userdomain: " + e.userdomain);
}