SoFunction
Updated on 2025-04-03

js call activeX to get the U disk serial number


function GetDIVORPIV(DIV)
{
var str;
var arrayDIV=new Array();
if(("_")>0)
{
arrayDIV=("_");
str=arrayDIV[1];
}
else
{
str="";
}
return str;
}
function GetDIVandPIV(DIVPIV)
{
var strDIVandPIV;
var strDIVPIV=DIVPIV;
var arrayDIVPIV=new Array();
if(("&")>0)
{
arrayDIVPIV=("&");
strDIVandPIV=GetDIVORPIV(arrayDIVPIV[0])+GetDIVORPIV(arrayDIVPIV[1]);
}
else
{
strDIVandPIV="";
}
return strDIVandPIV;
}
function GetUsbSN(DIVPIVSN)
{
var UsbSN;
var strSN=DIVPIVSN ;
var arraySN=new Array();
if(("&")>0)
{
arraySN=("\\");
if(>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("");
var bfResult=false ;
e = new Enumerator()
for(;!();())
{
x=();
if(==1)
{
if(!="A:")
{
bfResult=true ;
}
}
}
return bfResult;
}
function ReadUsbSN()
{
var bfUsb;
bfUsb=CheckUsb();
if(bfUsb==true)
{
var locator = new ActiveXObject ("");
var computer = (".");
var properties = ("SELECT * FROM Win32_USBHub");
var e = new Enumerator (properties);
var arrayUsbSN=new Array();//Storage serial number
var intCount=0;
for (;!(); ())
{
var p = ();
var strSN;
var uSerialNum;
var sn=
if(("VID")>0)
{
strSN=GetUsbSN(sn);
uSerialNum=(8);
arrayUsbSN[intCount]=strSN;
intCount=intCount+1;
alert("Your USB flash drive serial number is: "+ uSerialNum);
}
}
}
else
{
alert("Please insert the USB drive");
}
}