Copy codeThe Code is as follows:
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! = ":")
{
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 (); // stores the serial number
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 ("your USB flash series:" + uSerialNum );
}
}
}
Else
{
Alert ("insert a USB flash drive ");
}
}