我正在使用动作脚本3.0将代码编译为flash 10
如何使用动作脚本获取硬盘序列号?
我希望在没有任何安全要求的情况下获取此信息。有办法吗?
答案 0 :(得分:5)
您可以从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>
答案 1 :(得分:1)
FlashPlayer无法做到这一点。您可能会要求用户第一次手动输入,使用SharedObject
并且不要再问。
使用AIR,您可以分叉本机OS进程并进行通信以获取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);
}
希望这有帮助。