flex air app - 获取用户的AD域

时间:2010-08-17 12:49:51

标签: actionscript-3 air flex4

使用Flex 4 / Air 2.0.3

是否可以获取与登录用户关联的活动目录域名?

此页面(Get the current logged in OS user in Adobe Air)显示可以从用户目录文件夹名称推断出用户名,但有没有办法获取域名? (这假设用户是域的一部分!)

假设我是域“办公室”的一部分而我的登录名是“j.jones”,我想要检索“j.jones”和“office”部分。

谢谢,

Jonsie

2 个答案:

答案 0 :(得分:0)

AIR 2.0能够运行本机进程并读取其标准输出。因此,如果您的计算机安装了AD控制台工具,则可以从AIR运行 dsget user 并读取结果。此外,您可以使用您的程序使用工具(我已经创建了与java运行时捆绑在一起的AIR distrib)。

答案 1 :(得分:0)

我上过这堂课:

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);

    }