First, create the External Function called GetVolumeInformation, which taken from Kernel32.dll
1: FUNCTION long GetVolumeInformation &
2: (string lpRootPathName, REF string lpVolumeNameBuffer, &
3: long nVolumeNameSize, &
4: REF long lpVolumeSerialNumber, REF long lpMaximumComponentLength, &
5: REF long lpFileSystemFlags, REF string lpFileSystemNameBuffer, &
6: long nFileSystemNameSize) &
7: LIBRARY "Kernel32.dll" ALIAS FOR "GetVolumeInformationA"
Create the Window Function called of_long2hex with al_number and ai_digit as parameters, and the function will returns string. al_number is long type and ai_digit is integer type. The function is for converting Long value to Hex Value.
Type the script below:
1: long ll_temp0, ll_temp1
2: char lc_ret
3:
4: IF ai_digit > 0 THEN
5: ll_temp0 = abs(al_number / (16 ^ (ai_digit - 1)))
6: ll_temp1 = ll_temp0 * (16 ^ (ai_digit - 1))
7: IF ll_temp0 > 9 THEN
8: lc_ret = char(ll_temp0 + 55)
9: ELSE
10: lc_ret = char(ll_temp0 + 48)
11: END IF
12: RETURN lc_ret + of_long2hex(al_number - ll_temp1 , ai_digit - 1)
13: END IF
14: RETURN ""
Finally, create another Window Function called of_getserialnumber with strrootpath as parameter, and the function will returns string. I believe strrootpath is a string variable type. Beside the hard drive serial number, this function will return another variables, like Volume Name of the hard drive (ls_volbuffer) and File system name (ls_fsname) like FAT32 or NTFS.
Next, type this script below:
1: String ls_volbuffer, ls_fsname, sReturn
2: Long ll_serial, ll_MaxCompLength, ll_FileSystemFlags, ll_rtn
3:
4: ls_volbuffer = Space(255)
5: ls_fsname = Space(255)
6: ll_maxCompLength = 0
7: ll_FileSystemFlags = 0
8:
9: ll_rtn = GetVolumeinformation(strrootpath , ls_volbuffer, 255, ll_serial, &
10: ll_MaxCompLength, ll_FileSystemFlags , ls_fsname, 255)
11:
12: sReturn = of_long2hex(abs(ll_serial),8)
13: return left(sReturn,4)+"-"+right(sReturn,4)
To use the script, just create a simple script like below
1: String ls_SN
2:
3: ls_SN = of_getserialnumber("C:\")
4:
5: MessageBox("Your Hard Drive SN",ls_SN)
No comments:
Post a Comment