1

I was wondering if an AIR application can find out what OS it's running on, e.g. Windows XP, Vista, Mac OS, etc. Also, is there a way for it to find out the current OS user name? Thanks.

Tong Wang
  • 1,602
  • 4
  • 29
  • 36

2 Answers2

4

As @TML stated, System.Capabilities.os will get you the operating system. Now I don't know of any direct way to get the user name, but AIR file class has a userDirectory property that will give you a reference to the logged in user's home directory. The nativePath of that object ought to have the logged in user's name.

//user directory path normally ends with the user name like
//xp   : C:\Documents and Settings\userName
//mac  : /Users/userName
//*nix : /home/username or /home/groupname/username

var os:String = System.Capabilities.os;
var usr:String = File.userDirectory.nativePath;
var sep:String = File.separator;
if(usr.charAt(usr.length - 1) == sep)
  usr = usr.substring(0, usr.length - 1);//remove trailing slash
usr = usr.substring(usr.lastIndexOf(sep) + 1);
trace(usr);

Test with various OS's and find if there are any edge cases before using this in production code (like cases where user name is not the last part of the user directory - I am not aware of any, but just in case).

Amarghosh
  • 58,710
  • 11
  • 92
  • 121
2

Check into flash.system.Capabilities - I believe it has what you're looking for.

Acutally, it turns out this is a duplicate question: Get Current Operating System In Adobe Air

Community
  • 1
  • 1
TML
  • 12,813
  • 3
  • 38
  • 45
  • Thanks. What about the currently logged in OS user? – Tong Wang Jan 08 '10 at 18:12
  • 1
    I'm pretty sure you can't get that - that information shouldn't be available to flash at all. – TML Jan 08 '10 at 19:47
  • Through native process open the commandline and execute the command echo %username%. get output of this command :) Although its not a perfect solution, but through this trick you can do that. – Mudasir Bhutto Apr 10 '11 at 15:05