Exemple pour le numéro de série du disque dur (d'après un code de Rings).
Fonctionne aussi sous Win9x.
Code : Tout sélectionner
Procedure.s ChangeHighLowByte(Instring.s) ;Change Big-Little Endian
Protected sdummy.s, l.l, I.l
l = Len(Instring)
For I = 1 To l Step 2
If (I + 1) <= l
sdummy = sdummy + Mid(Instring, I + 1, 1) + Mid(Instring, I, 1)
EndIf
Next I
ProcedureReturn sdummy
EndProcedure
Structure IDEREGS
bFeaturesReg.b
bSectorCountReg.b
bSectorNumberReg.b
bCylLowReg.b
bCylHighReg.b
bDriveHeadReg.b
bCommandReg.b
bReserved.b
EndStructure
Structure DRIVERSTATUS
bDriveError.b
bIDEStatus.b
bReserved.b[2]
dwReserved.l[2]
EndStructure
Structure SENDCMDINPARAMS
cBufferSize.l
irDriveRegs.IDEREGS
bDriveNumber.b
bReserved.b[3]
dwReserved.l[4]
EndStructure
Structure SENDCMDOUTPARAMS
cBufferSize.l
DStatus.DRIVERSTATUS
bBuffer.b[512]
EndStructure
#DFP_RECEIVE_DRIVE_DATA = $7C088
ProcedureDLL.s GetDriveSerial(PhysicalDrive.l) ; Retrieves physical drive serial [empty string if failed]
Protected mvarCurrentDrive.l, VersionInfo.OSVERSIONINFO, Platform.l, hdh.l, br.l, Result.l
Protected bin.SENDCMDINPARAMS, bout.SENDCMDOUTPARAMS, Serial.s
If PhysicalDrive >= 0 And PhysicalDrive <= 255
VersionInfo\dwOSVersionInfoSize = SizeOf(OSVERSIONINFO)
Platform = GetVersionEx_(VersionInfo)
If Platform
If VersionInfo\dwPlatformId = #VER_PLATFORM_WIN32_WINDOWS ; Win9x/Me
hdh = CreateFile_("\\.\SMARTVSD", #GENERIC_READ, #FILE_SHARE_READ, 0, #OPEN_EXISTING, 0, 0)
Else ; NT kernel
hdh = CreateFile_("\\.\PhysicalDrive" + Str(PhysicalDrive), #GENERIC_READ | #GENERIC_WRITE, #FILE_SHARE_READ | #FILE_SHARE_WRITE, 0, #OPEN_EXISTING, 0, 0)
EndIf
EndIf
If hdh <> #INVALID_HANDLE_VALUE
bin\bDriveNumber = PhysicalDrive
bin\cBufferSize = 512
If PhysicalDrive & 1
bin\irDriveRegs\bDriveHeadReg = $B0
Else
bin\irDriveRegs\bDriveHeadReg = $A0
EndIf
bin\irDriveRegs\bCommandReg = $EC
bin\irDriveRegs\bSectorCountReg = 1
bin\irDriveRegs\bSectorNumberReg = 1
Result = DeviceIoControl_(hdh, #DFP_RECEIVE_DRIVE_DATA, bin, SizeOf(SENDCMDINPARAMS), bout, SizeOf(SENDCMDOUTPARAMS), @br, 0)
If br > 0
Serial = Trim(ChangeHighLowByte(PeekS(@bout\bBuffer[0] + 20, 20)))
EndIf
EndIf
EndIf
ProcedureReturn Serial
EndProcedure
Debug GetDriveSerial(0)