4 Replies Latest reply on Mar 16, 2010 6:26 AM by panosru*

    Getting the user name and computer name

    MixMastaJames Level 1

      I've been trying to find out how to do this, but can't seem to get it.

       

      I have an AIR application that needs to get the user's login name, and computer name for verification.  I can't find anywhere to do this.  Is AIR able to get this information? Is there work arounds if there isn't?

       

      It won't ever be a web app, just an AIR app.

        • 1. Re: Getting the user name and computer name
          MixMastaJames Level 1

          is there no way to do this?

          • 2. Re: Getting the user name and computer name
            panosru* Level 1

            Same question.... Although now we almost have Air 2 so I could ask again if the above is possible with Air 2?

             

            Thanks

            • 3. Re: Getting the user name and computer name
              MixMastaJames Level 1

              Never did figure it out.....

              • 4. Re: Getting the user name and computer name
                panosru* Level 1

                What I did in Air 2 to accomplish that is the following:

                 

                               public function getHostName():void {
                                    if(NativeProcess.isSupported) {
                                         var OS:String = Capabilities.os.toLocaleLowerCase();
                                         var file:File;
                                         
                                         if (OS.indexOf('win') > -1) {
                                              //Executable in windows
                                              file = new File('C:\\Windows\\System32\\hostname.exe');
                                         } else if (OS.indexOf('mac') > -1 ) {
                                              //Executable in mac
                                         } else if (OS.indexOf('linux')) {
                                              //Executable in linux
                                         }
                                         
                                         var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
                                         nativeProcessStartupInfo.executable = file;
                                         
                                         var process:NativeProcess = new NativeProcess();
                                              process.addEventListener(NativeProcessExitEvent.EXIT, onExitError);
                                              process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutput);
                                              process.start(nativeProcessStartupInfo);
                                              process.closeInput();
                                    }
                               }
                               
                               import utls.StringHelper;
                               public function onOutput(event:ProgressEvent):void {
                                    var strHelper:StringHelper = new StringHelper();
                                    var output:String = event.target.standardOutput.readUTFBytes(event.target.standardOutput.bytesAvailable);
                                         output = strHelper.trimBack(output, "\n");
                                         output = strHelper.trimBack(output, "\r");
                                    
                                    trace('"'+output+'"');
                               }
                

                 

                The package that I used is from the manual:

                package utls
                {
                     public class StringHelper
                     {
                          public function StringHelper()
                          {
                          }
                          
                          public function replace(str:String, oldSubStr:String, newSubStr:String):String {
                               return str.split(oldSubStr).join(newSubStr);
                          }
                          
                          public function trim(str:String, char:String):String {
                               return trimBack(trimFront(str, char), char);
                          }
                          
                          public function trimFront(str:String, char:String):String {
                               char = stringToCharacter(char);
                               if (str.charAt(0) == char) {
                                    str = trimFront(str.substring(1), char);
                               }
                               return str;
                          }
                          
                          public function trimBack(str:String, char:String):String {
                               char = stringToCharacter(char);
                               if (str.charAt(str.length - 1) == char) {
                                    str = trimBack(str.substring(0, str.length - 1), char);
                               }
                               return str;
                          }
                          
                          public function stringToCharacter(str:String):String {
                               if (str.length == 1) {
                                    return str;
                               }
                               return str.slice(0, 1);
                          }
                     }
                }
                

                 

                And sorry for the miss topic I just realized that it is on flex topic, but I post it either way it may be useful for anyone