Home > Web Front-end > JS Tutorial > js calls activeX to get the USB disk serial number code_javascript skills

js calls activeX to get the USB disk serial number code_javascript skills

WBOY
Release: 2016-05-16 17:59:16
Original
1863 people have browsed it
复制代码 代码如下:

function GetDIVORPIV(DIV)
{
var str;
var arrayDIV=new Array();
if(DIV.indexOf("_")>0)
{
arrayDIV=DIV.split("_");
str=arrayDIV[1];
}
else
{
str="";
}
return str;
}
function GetDIVandPIV(DIVPIV)
{
var strDIVandPIV;
var strDIVPIV=DIVPIV;
var arrayDIVPIV=new Array();
if(strDIVPIV.indexOf("&")>0)
{
arrayDIVPIV=strDIVPIV.split("&");
strDIVandPIV=GetDIVORPIV(arrayDIVPIV[0]) GetDIVORPIV(arrayDIVPIV[1]);
}
else
{
strDIVandPIV="";
}
return strDIVandPIV;
}
function GetUsbSN(DIVPIVSN)
{
var UsbSN;
var strSN=DIVPIVSN ;
var arraySN=new Array();
if(strSN.indexOf("&")>0)
{
arraySN=strSN.split("\");
if(arraySN.length>2)
{
UsbSN=GetDIVandPIV(arraySN[1]) arraySN[2];
}
else
{
UsbSN="";
}
}
else
{
UsbSN="";
}
return UsbSN;
}
function CheckUsb()
{
var e,x;
var ForReading = 1,RorWriting = 2;
var fso = new ActiveXObject("Scripting.FileSystemObject");
var bfResult=false ;
e = new Enumerator(fso.Drives)
for(;!e.atEnd();e.moveNext())
{
x=e.item();
if(x.DriveType==1)
{
if(x.Path!="A:")
{
bfResult=true ;
}
}
}
return bfResult;
}
function ReadUsbSN()
{
var bfUsb;
bfUsb=CheckUsb();
if(bfUsb==true)
{
var locator = new ActiveXObject ("WbemScripting.SWbemLocator");
var computer = locator.ConnectServer(".");
var properties = computer.ExecQuery("SELECT * FROM Win32_USBHub");
var e = new Enumerator (properties);
var arrayUsbSN=new Array();//存放序列号
var intCount=0;
for (;!e.atEnd();e.moveNext ())
{
var p = e.item ();
var strSN;
var uSerialNum;
var sn=p.DeviceID
if(sn.indexOf("VID")>0)
{
strSN=GetUsbSN(sn);
uSerialNum=strSN.substring(8);
arrayUsbSN[intCount]=strSN;
intCount=intCount 1;
alert("你的U盘系列号为:" uSerialNum);
}
}
}
else
{
alert("请插入U盘");
}
}
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template