如何使用动作脚本获取硬盘序列号

发布于 2024-11-28 00:01:23 字数 114 浏览 1 评论 0原文

我正在使用action script 3.0将代码编译到flash 10

如何使用action script获取硬盘序列号?

我想在没有任何安全要求的情况下获取此信息。有办法做到吗?

I'm using action script 3.0 compiling the code to flash 10

how to get hard disk serial number with action script?

I want to get this info without any security requirement. Is there a way to do it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

油焖大侠 2024-12-05 00:01:23

您可以从 C# 控制台应用程序获取设备的所有物理介质,并将每个物理介质及其属性输出为 xml。然后,在使用 NativeApplication API 的 Air 应用程序中,您可以获得所述物理介质及其属性,即硬盘驱动器的序列号。我做了一个这样的例子:

GetPhysicalMedia.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Management;

namespace GetPhysicalMedia
{
    class Program
    {
        static void Main(string[] args)
        {
            ManagementClass managementClass = new ManagementClass("Win32_PhysicalMedia");

            String physicalMediaXml = "";

            physicalMediaXml += "<physicalMedia>\n";

            foreach (ManagementObject managementObject in managementClass.GetInstances())
            {
                physicalMediaXml += "\t<physicalMedium ";
                physicalMediaXml += "caption" + "='" + managementObject["Caption"] + "' ";
                physicalMediaXml += "description" + "='" + managementObject["Description"] + "' ";
                physicalMediaXml += "installDate" + "='" + managementObject["InstallDate"] + "' ";
                physicalMediaXml += "name" + "='" + managementObject["Name"] + "' ";
                physicalMediaXml += "status" + "='" + managementObject["Status"] + "' ";
                physicalMediaXml += "creationClassName" + "='" + managementObject["CreationClassName"] + "' ";
                physicalMediaXml += "manufacturer" + "='" + managementObject["Manufacturer"] + "' ";
                physicalMediaXml += "model" + "='" + managementObject["Model"] + "' ";
                physicalMediaXml += "sku" + "='" + managementObject["SKU"] + "' ";
                physicalMediaXml += "serialNumber" + "='" + managementObject["SerialNumber"] + "' ";
                physicalMediaXml += "tag" + "='" + Regex.Replace((String)managementObject["Tag"], "\\\\", "\") +"' ";
                physicalMediaXml += "version" + "='" + managementObject["Version"] + "' ";
                physicalMediaXml += "partNumber" + "='" + managementObject["PartNumber"] + "' ";
                physicalMediaXml += "otherIdentifyingInfo" + "='" + managementObject["OtherIdentifyingInfo"] + "' ";
                physicalMediaXml += "poweredOn" + "='" + managementObject["PoweredOn"] + "' ";
                physicalMediaXml += "removable" + "='" + managementObject["Removable"] + "' ";
                physicalMediaXml += "replaceable" + "='" + managementObject["Replaceable"] + "' ";
                physicalMediaXml += "hotSwappable" + "='" + managementObject["HotSwappable"] + "' ";
                physicalMediaXml += "capacity" + "='" + managementObject["Capacity"] + "' ";
                physicalMediaXml += "mediaType" + "='" + managementObject["MediaType"] + "' ";
                physicalMediaXml += "mediaDescription" + "='" + managementObject["MediaDescription"] + "' ";
                physicalMediaXml += "writeProtectOn" + "='" + managementObject["WriteProtectOn"] + "' ";
                physicalMediaXml += "cleanerMedia" + "='" + managementObject["CleanerMedia"] + "' ";
                physicalMediaXml += "/>\n";

            }// end foreach

            physicalMediaXml += "</physicalMedia>\n";

            Console.WriteLine(physicalMediaXml);

        }// end method

    }// end class

}// end namespace

Main.as:

package 
{
    import flash.desktop.NativeProcess;
    import flash.desktop.NativeProcessStartupInfo;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.ProgressEvent;
    import flash.filesystem.File;

    public class Main extends Sprite 
    {
        private var _nativeProcess:NativeProcess;
        private var _nativeProcessSUI:NativeProcessStartupInfo;
        private var _physicalMedia:XML;

        public function Main():void 
        {
            _nativeProcess = new NativeProcess();
            _nativeProcessSUI = new NativeProcessStartupInfo();

            _nativeProcessSUI.executable = File.applicationDirectory.resolvePath("GetPhysicalMedia.exe");
            _nativeProcess.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onNativeProcessSOD);
            _nativeProcess.addEventListener(Event.STANDARD_OUTPUT_CLOSE, onNativeProcessSOC);
            _nativeProcess.start(_nativeProcessSUI);

        }// end function

        private function onNativeProcessSOD(e:ProgressEvent):void
        {
            _physicalMedia = XML(_nativeProcess.standardOutput.readUTFBytes(_nativeProcess.standardOutput.bytesAvailable));

        }// end function

        private function onNativeProcessSOC(e:Event):void
        {
            trace(_physicalMedia.physicalMedium.(String(@tag).search("PHYSICALDRIVE0") > -1).@serialNumber); // output: V5FEVZ2W
            trace(_physicalMedia.physicalMedium.(String(@tag).search("PHYSICALDRIVE1") > -1).@serialNumber); // output: WD-WCASU2856512 

        }// end function

    }// end class

}// end package

这是 GetPhysicalMedia.exe 的输出示例:

<physicalMedia>
  <physicalMedium caption="" description="" installDate="" name="" status="" creationClassName="" manufacturer="" model="" sku="" serialNumber="V5FEVZ2W            " tag="\\.\PHYSICALDRIVE0" version="" partNumber="" otherIdentifyingInfo="" poweredOn="" removable="" replaceable="" hotSwappable="" capacity="" mediaType="" mediaDescription="" writeProtectOn="" cleanerMedia=""/>
  <physicalMedium caption="" description="" installDate="" name="" status="" creationClassName="" manufacturer="" model="" sku="" serialNumber="WD-WCASU2856512     " tag="\\.\PHYSICALDRIVE1" version="" partNumber="" otherIdentifyingInfo="" poweredOn="" removable="" replaceable="" hotSwappable="" capacity="" mediaType="" mediaDescription="" writeProtectOn="" cleanerMedia=""/>
  <physicalMedium caption="" description="" installDate="" name="" status="" creationClassName="" manufacturer="" model="" sku="" serialNumber="516256L411          " tag="\\.\CDROM0" version="" partNumber="" otherIdentifyingInfo="" poweredOn="" removable="" replaceable="" hotSwappable="" capacity="" mediaType="" mediaDescription="" writeProtectOn="" cleanerMedia=""/>
</physicalMedia>

You could get all the physical media for a device from a C# console application and output each physical medium and its properties as an xml. Then in an Air application using the NativeApplication API you can get said physical medium and its properties, namely the serial number for a hard disk drive. I made an example of this:

GetPhysicalMedia.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Management;

namespace GetPhysicalMedia
{
    class Program
    {
        static void Main(string[] args)
        {
            ManagementClass managementClass = new ManagementClass("Win32_PhysicalMedia");

            String physicalMediaXml = "";

            physicalMediaXml += "<physicalMedia>\n";

            foreach (ManagementObject managementObject in managementClass.GetInstances())
            {
                physicalMediaXml += "\t<physicalMedium ";
                physicalMediaXml += "caption" + "='" + managementObject["Caption"] + "' ";
                physicalMediaXml += "description" + "='" + managementObject["Description"] + "' ";
                physicalMediaXml += "installDate" + "='" + managementObject["InstallDate"] + "' ";
                physicalMediaXml += "name" + "='" + managementObject["Name"] + "' ";
                physicalMediaXml += "status" + "='" + managementObject["Status"] + "' ";
                physicalMediaXml += "creationClassName" + "='" + managementObject["CreationClassName"] + "' ";
                physicalMediaXml += "manufacturer" + "='" + managementObject["Manufacturer"] + "' ";
                physicalMediaXml += "model" + "='" + managementObject["Model"] + "' ";
                physicalMediaXml += "sku" + "='" + managementObject["SKU"] + "' ";
                physicalMediaXml += "serialNumber" + "='" + managementObject["SerialNumber"] + "' ";
                physicalMediaXml += "tag" + "='" + Regex.Replace((String)managementObject["Tag"], "\\\\", "\") +"' ";
                physicalMediaXml += "version" + "='" + managementObject["Version"] + "' ";
                physicalMediaXml += "partNumber" + "='" + managementObject["PartNumber"] + "' ";
                physicalMediaXml += "otherIdentifyingInfo" + "='" + managementObject["OtherIdentifyingInfo"] + "' ";
                physicalMediaXml += "poweredOn" + "='" + managementObject["PoweredOn"] + "' ";
                physicalMediaXml += "removable" + "='" + managementObject["Removable"] + "' ";
                physicalMediaXml += "replaceable" + "='" + managementObject["Replaceable"] + "' ";
                physicalMediaXml += "hotSwappable" + "='" + managementObject["HotSwappable"] + "' ";
                physicalMediaXml += "capacity" + "='" + managementObject["Capacity"] + "' ";
                physicalMediaXml += "mediaType" + "='" + managementObject["MediaType"] + "' ";
                physicalMediaXml += "mediaDescription" + "='" + managementObject["MediaDescription"] + "' ";
                physicalMediaXml += "writeProtectOn" + "='" + managementObject["WriteProtectOn"] + "' ";
                physicalMediaXml += "cleanerMedia" + "='" + managementObject["CleanerMedia"] + "' ";
                physicalMediaXml += "/>\n";

            }// end foreach

            physicalMediaXml += "</physicalMedia>\n";

            Console.WriteLine(physicalMediaXml);

        }// end method

    }// end class

}// end namespace

Main.as:

package 
{
    import flash.desktop.NativeProcess;
    import flash.desktop.NativeProcessStartupInfo;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.ProgressEvent;
    import flash.filesystem.File;

    public class Main extends Sprite 
    {
        private var _nativeProcess:NativeProcess;
        private var _nativeProcessSUI:NativeProcessStartupInfo;
        private var _physicalMedia:XML;

        public function Main():void 
        {
            _nativeProcess = new NativeProcess();
            _nativeProcessSUI = new NativeProcessStartupInfo();

            _nativeProcessSUI.executable = File.applicationDirectory.resolvePath("GetPhysicalMedia.exe");
            _nativeProcess.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onNativeProcessSOD);
            _nativeProcess.addEventListener(Event.STANDARD_OUTPUT_CLOSE, onNativeProcessSOC);
            _nativeProcess.start(_nativeProcessSUI);

        }// end function

        private function onNativeProcessSOD(e:ProgressEvent):void
        {
            _physicalMedia = XML(_nativeProcess.standardOutput.readUTFBytes(_nativeProcess.standardOutput.bytesAvailable));

        }// end function

        private function onNativeProcessSOC(e:Event):void
        {
            trace(_physicalMedia.physicalMedium.(String(@tag).search("PHYSICALDRIVE0") > -1).@serialNumber); // output: V5FEVZ2W
            trace(_physicalMedia.physicalMedium.(String(@tag).search("PHYSICALDRIVE1") > -1).@serialNumber); // output: WD-WCASU2856512 

        }// end function

    }// end class

}// end package

This is an example of the output you get for GetPhysicalMedia.exe:

<physicalMedia>
  <physicalMedium caption="" description="" installDate="" name="" status="" creationClassName="" manufacturer="" model="" sku="" serialNumber="V5FEVZ2W            " tag="\\.\PHYSICALDRIVE0" version="" partNumber="" otherIdentifyingInfo="" poweredOn="" removable="" replaceable="" hotSwappable="" capacity="" mediaType="" mediaDescription="" writeProtectOn="" cleanerMedia=""/>
  <physicalMedium caption="" description="" installDate="" name="" status="" creationClassName="" manufacturer="" model="" sku="" serialNumber="WD-WCASU2856512     " tag="\\.\PHYSICALDRIVE1" version="" partNumber="" otherIdentifyingInfo="" poweredOn="" removable="" replaceable="" hotSwappable="" capacity="" mediaType="" mediaDescription="" writeProtectOn="" cleanerMedia=""/>
  <physicalMedium caption="" description="" installDate="" name="" status="" creationClassName="" manufacturer="" model="" sku="" serialNumber="516256L411          " tag="\\.\CDROM0" version="" partNumber="" otherIdentifyingInfo="" poweredOn="" removable="" replaceable="" hotSwappable="" capacity="" mediaType="" mediaDescription="" writeProtectOn="" cleanerMedia=""/>
</physicalMedia>
痴梦一场 2024-12-05 00:01:23

FlashPlayer 无法做到这一点。您可能会要求用户第一次手动输入,使用 SharedObject 并且不再询问。

使用 AIR,您可以分叉本机操作系统进程并与其进行通信以获取 HDD 序列号:

var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();  
var file:File = File.applicationDirectory.resolvePath("some_hdd_utility.exe");  
nativeProcessStartupInfo.executable = file;  
var processArgs:Vector.<String> = new Vector.<String>();  
processArgs.push("someArgs");  
nativeProcessStartupInfo.arguments = processArgs;  
process = new NativeProcess();  
process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);  
process.start(nativeProcessStartupInfo);  
public function onOutputData(event:ProgressEvent):void  
{  
    var stdOut:ByteArray = process.standardOutput;  
    var data:String = stdOut.readUTFBytes(process.standardOutput.bytesAvailable);  
    trace("Got: ", data);  
}

希望这会有所帮助。

There is no way to do that from FlashPlayer. You might ask for the user to type it manually the first time, use a SharedObject and never ask again.

With AIR you can fork native OS process and communicate it to obtain HDD serial number:

var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();  
var file:File = File.applicationDirectory.resolvePath("some_hdd_utility.exe");  
nativeProcessStartupInfo.executable = file;  
var processArgs:Vector.<String> = new Vector.<String>();  
processArgs.push("someArgs");  
nativeProcessStartupInfo.arguments = processArgs;  
process = new NativeProcess();  
process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);  
process.start(nativeProcessStartupInfo);  
public function onOutputData(event:ProgressEvent):void  
{  
    var stdOut:ByteArray = process.standardOutput;  
    var data:String = stdOut.readUTFBytes(process.standardOutput.bytesAvailable);  
    trace("Got: ", data);  
}

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文