Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
923 views
in Technique[技术] by (71.8m points)

windows - Retrieve manufacturer information from device that AIR app is running on

Does anybody know of a way to retrieve information about the manufacturer/model of the device that the AIR app is running on. The Capabilities class doesn't seem to cut it.

The solution only needs to work for AIR apps running on Windows desktops or laptops, and it needn't be a descriptive string of the model - as long as it is a piece of data unique to a specific model or device (or at least the specific manufacturer).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

On Windows, it's possible to query the motherboard's serial number with WMIC, or Windows Management Instrumentation Command-line. Therefore, you can simply pass the command wmic baseboard get serialnumber as an argument to cmd.exe using flash.desktop.NativeProcess without the need for a Native Extension.

Since the AIR NativeProcess API is being used, you must use the Extended Desktop application profile and package your application with a native installer.

package 
{
    //Imports
    import flash.display.Sprite;
    import flash.display.StageScaleMode;
    import flash.display.StageAlign;
    import flash.desktop.NativeProcess;
    import flash.desktop.NativeProcessStartupInfo;
    import flash.events.ProgressEvent;
    import flash.filesystem.File;

    //Class
    [SWF(width = "600", height = "250", frameRate = "60", backgroundColor = "0x000000")]
    public class Main extends Sprite 
    {
        //Constants
        private static const MOTHERBOARD_SERIALNUMBER_COMMAND:String = "wmic baseboard get serialnumber";

        //Properties
        private var nativeProcess:NativeProcess;

        //Constructor
        public function Main():void 
        {
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;

            init();
        }       

        //Init
        private function init():void
        {
            if (!NativeProcess.isSupported)
            {
                throw new Error("Native Process is not supported.");
            }

            var file:File = new File("C:\Windows\System32\cmd.exe");

            var args:Vector.<String> = new Vector.<String>();
            args.push("/c");
            args.push(MOTHERBOARD_SERIALNUMBER_COMMAND);

            var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
            nativeProcessStartupInfo.executable = file;         
            nativeProcessStartupInfo.arguments = args;

            nativeProcess = new NativeProcess(); 
            nativeProcess.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, outputDataEventHandler);
            nativeProcess.addEventListener(ProgressEvent.STANDARD_ERROR_DATA, outputErrorEventHandler);
            nativeProcess.start(nativeProcessStartupInfo);
        }

        //Output Data Event Handler
        private function outputDataEventHandler(event:ProgressEvent):void 
        { 
            var output:String = nativeProcess.standardOutput.readUTFBytes(nativeProcess.standardOutput.bytesAvailable);

            nativeProcess.exit();

            trace(output);
        }

        //Output Error Event Handler
        private function outputErrorEventHandler(event:ProgressEvent):void
        {
            nativeProcess.exit();

            throw new Error(event);
        }
    }
}

[EDIT]

Alternatively, if you would also like to retreive the motherboard's manufacturer, model number and serial number, you can update the string constant to this:

//Constants
private static const MOTHERBOARD_INFO:String = "wmic baseboard get product, manufacturer, serialnumber";

[EDIT 2]

I just learned that the following WMIC command will return the name, vendor and identifying number of a machine. It sounds exactly what your looking for:

//Constants
private static const CSPRODUCT_INFO:String = "wmic csproduct get name, vendor, identifyingNumber";

However, keep in mind that for custom built PCs, such as my own, this command returns nothing. Well, not exactly nothing, but instead of something typical like:

IdentifyingNumber  Name           Vendor
99L9891            Latitude D610  Dell Inc.

My custom build returns this:

IdentifyingNumber     Name                 Vendor
System Serial Number  System Product Name  System manufacturer

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...