현재 로그인됨 사용자 이름을 데릭쉐퍼드와 내 항공기 / 플렉스 응용 프로그램. 응용 프로그램이 윈도우 시스템을 구축할 수 있을 뿐이다. 저는 이것을 가능하게 할 수 있지만, 다른 길을 열 수 있는 사용자 디렉토리에는 리자오싱 키워봤지.
package
{
import flash.filesystem.File;
public class UserUtil
{
public static function get currentOSUser():String
{
var userDir:String = File.userDirectory.nativePath;
var userName:String = userDir.substr(userDir.lastIndexOf(File.separator) + 1);
return userName;
}
}
}
케빈 제안됩니다 사용할 수 있다 ',' file.스파이터 디렉토리에는 분할 크로스 플랫폼 (Windows, Mac OS X 그냥 테스트되었습니다).
또한 이 기능을 사용하면 적절한 킬러 바인딩하면 userdic. 없이 넘기면서 작동합니까.
위의 예에서 I put it 를 '우저우틸' 클래스 ',' 우저우틸.커엔토스우저 바인딩하지 에드그, 이젠 할 수 있습니다.
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Label text="{UserUtil.currentOSUser}"/>
</mx:WindowedApplication>
public var username:String;
public function getCurrentOSUser():void
{
var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
var file:File = new File("C:/WINDOWS/system32/whoami.exe");
nativeProcessStartupInfo.executable = file;
process = new NativeProcess();
process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
process.start(nativeProcessStartupInfo);
}
public function onOutputData(event:ProgressEvent):void
{
var output:String = process.standardOutput.readUTFBytes(process.standardOutput.bytesAvailable);
this.username = output.split('\\')[1];
trace("Got username: ", this.username);
}
이 솔루션은 XP / Vista 에 OSX 에서 작동하는 것이 아니라 말해둘꼐요 확장가능 linix I& # 39; d 여전히 관심을 가질 수 있는 다른 방법을.
public static function GetCurrentOSUser():String{
// XP & Vista only.
var userDirectory:String = File.userDirectory.resolvePath("").nativePath;
var startIndex:Number = userDirectory.lastIndexOf("\\") + 1
var stopIndex:Number = userDirectory.length;
var user = userDirectory.substring(startIndex, stopIndex);
return user;
}