Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 在AdobeAIR中获取计算机名_Actionscript 3_Flex4_Air_Flexbuilder_Flash Builder - Fatal编程技术网

Actionscript 3 在AdobeAIR中获取计算机名

Actionscript 3 在AdobeAIR中获取计算机名,actionscript-3,flex4,air,flexbuilder,flash-builder,Actionscript 3,Flex4,Air,Flexbuilder,Flash Builder,大家好: 谁能告诉我如何使用AdobeAIR获取本地计算机名 请尽快回复我。提前谢谢。这可能会奏效 最后一页 我在Air 2中所做的工作如下: 我使用的软件包来自手册: 谢谢但我已经用过那种类型了。问题是,我不仅要为Windows创建应用程序,还要为MAC和linux创建应用程序。所以,这就是为什么我不能遵循这个方法。我不知道MAC和Linux中是否存在此类应用程序(主机名)。顺便说一句,file=new file('C:\\Windows\\System32\\hostname.exe')是一

大家好: 谁能告诉我如何使用AdobeAIR获取本地计算机名


请尽快回复我。提前谢谢。

这可能会奏效

最后一页

我在Air 2中所做的工作如下:

我使用的软件包来自手册:


谢谢但我已经用过那种类型了。问题是,我不仅要为Windows创建应用程序,还要为MAC和linux创建应用程序。所以,这就是为什么我不能遵循这个方法。我不知道MAC和Linux中是否存在此类应用程序(主机名)。顺便说一句,
file=new file('C:\\Windows\\System32\\hostname.exe')是一种非常幼稚的运行方式。Windows可以安装在不同的位置。在Windows 2000中,有文件夹winnt。所以,这将是一个问题。但我们可以检查文件夹是否存在?它可能很有用,但仍然不是完美的解决方案。在Mac、Ubuntu或任何未安装在C:\Windows的Windows安装上也不起作用。@MudasirBhutto:我有类似的要求。你能在不同的操作系统中获取主机名吗?我没有要求提供操作系统和用户名。我要求提供主机名。此代码仅适用于Adobe Air work。但计算机可能会请求许可。[SWF]untitle-1.SWF-解压后1172字节操作系统:windows 7操作系统名称:DestekI要求获取计算机名,而不是用户名。明白吗?
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+'"');
}
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);  
          }  
     }  
}  
import flash.filesystem.File;

var OS:String = Capabilities.os.toLocaleLowerCase();

function currentOSUser():String { 
    var userDir:String = File.userDirectory.nativePath; 
    var userName:String = userDir.substr(userDir.lastIndexOf(File.separator) + 1); 
    return userName; 
}

trace( 'Os : ' + OS );
trace( 'Os Name: ' + currentOSUser() );