relax62
Messages postés82Date d'inscriptionvendredi 2 avril 2004StatutMembreDernière intervention 8 juillet 20121 22 déc. 2011 à 15:58
Bonjour,
Désolé pour le déterrage de post !
Il y a quelques adaptations à effectuer pour le faire tourner en .net (au niveau de la déclaration).
Voici ce que j'ai du mettre pour compiler :
Private Declare Auto Function GetVolumeInformation Lib "kernel32.dll" ( _
ByVal RootPathName As String, _
ByVal VolumeNameBuffer As System.Text.StringBuilder, _
ByVal VolumeNameSize As UInt32, _
ByRef VolumeSerialNumber As UInt32, _
ByRef MaximumComponentLength As UInt32, _
ByRef FileSystemFlags As UInt32, _
ByVal FileSystemNameBuffer As System.Text.StringBuilder, _
ByVal FileSystemNameSize As UInt32) As UInt32
En espérant que ça puisse servir...
Gnain
Messages postés37Date d'inscriptionvendredi 9 juin 2006StatutMembreDernière intervention29 avril 2011 10 sept. 2008 à 18:47
salut thony64270, malheureusement je ne peu t'aider car je ne suis pas encore passé a vista. Par contre si tu veut récupérer ce numéro pour un programme de sécurité, il est beaucoup plus façile de récupérer le numéros de série de windows au lieu du disque dur. Un code sources pour le numéros de série de windows est bon pour toute les machines peu importe la version.
thony64270
Messages postés13Date d'inscriptionsamedi 24 juin 2006StatutMembreDernière intervention 9 juillet 2009 9 sept. 2008 à 22:57
Gnain ton code ne marche pas sur toute les machine.
J'ai une machine vista qui renvoie rien.
bmwzezette
Messages postés2Date d'inscriptionlundi 29 septembre 2003StatutMembreDernière intervention18 février 2008 18 avril 2008 à 16:48
TRES TRES BIEN TON CODE GNAIN
questions:
Pour moi qui debute, comment faire POUR AFFICHER dans des MsgBox ou dans une fenetre texte le bDriveType, le nb de Cilinders, de heads,de SecPerTrack,et de BytesperSector ? merci par avance pour ta reponse et pour des exemples
playmore75
Messages postés3Date d'inscriptionmercredi 30 mai 2007StatutMembreDernière intervention16 décembre 2007 12 déc. 2007 à 23:28
thanks gain
Gnain
Messages postés37Date d'inscriptionvendredi 9 juin 2006StatutMembreDernière intervention29 avril 2011 4 mai 2007 à 19:43
Salut Lucky Hal
voici ce qu'il faut faire pour VB4-32 et VB5
suivre ces instructions.
Private Function SwapBytes(b() As Byte) As Byte()
'Note: VB4-32 and VB5 do not support the
'return of arrays from a function. For
'developers using these VB versions there
'are two workarounds to this restriction:
'
'1) Change the return data type ( As Byte() )
' to As Variant (no brackets). No change
' to the calling code is required.
'
'2) Change the function to a sub, remove
' the last line of code (SwapBytes = b()),
' and take advantage of the fact the
' original byte array is being passed
' to the function ByRef, therefore any
' changes made to the passed data are
' actually being made to the original data.
' With this workaround the calling code
' also requires modification:
'
' di.Model = StrConv(SwapBytes(IDSEC.sModelNumber), vbUnicode)
'
' ... to ...
'
' Call SwapBytes(IDSEC.sModelNumber)
' di.Model = StrConv(IDSEC.sModelNumber, vbUnicode)
Dim bTemp As Byte
Dim cnt As Long
For cnt = LBound(b) To UBound(b) Step 2
bTemp = b(cnt)
b(cnt) = b(cnt + 1)
b(cnt + 1) = bTemp
Next cnt
SwapBytes = b()
End Function
lucky hal
Messages postés22Date d'inscriptionjeudi 17 février 2005StatutMembreDernière intervention 4 février 2008 4 mai 2007 à 17:35
Bonjour,
J'aurais bien voulu tester le code de Gnain, mais je n'ai que vb2005, et donc plus d'une centaine d'erreurs a la compilation, j'ai essayer de passer ce code dans l'assistant de mise a jour du code vb6, mais il reste des erreurs que je n'arrive pas a corriger...Y aurait il quelqu'un qui pourrais traduire ce code pour vb2005 svp ?
Merci d'avance...
vbmarh
Messages postés60Date d'inscriptiondimanche 9 octobre 2005StatutMembreDernière intervention30 novembre 2010 3 mai 2007 à 03:34
Merci Gnain ca aide top
Gnain
Messages postés37Date d'inscriptionvendredi 9 juin 2006StatutMembreDernière intervention29 avril 2011 3 mai 2007 à 01:34
Voici le code qui va chercher le vraie numéro de serie du disque dur. Il vous faut un form1 et un textbox appelé text1
'***********placer ce code dans un form1**********
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
'GETVERSIONOUTPARAMS contains the data returned
'from the Get Driver Version function
Private Type GETVERSIONOUTPARAMS
bVersion As Byte 'Binary driver version.
bRevision As Byte 'Binary driver revision
bReserved As Byte 'Not used
bIDEDeviceMap As Byte 'Bit map of IDE devices
fCapabilities As Long 'Bit mask of driver capabilities
dwReserved(3) As Long 'For future use
End Type
'IDE registers
Private Type IDEREGS
bFeaturesReg As Byte 'Used for specifying SMART "commands"
bSectorCountReg As Byte 'IDE sector count register
bSectorNumberReg As Byte 'IDE sector number register
bCylLowReg As Byte 'IDE low order cylinder value
bCylHighReg As Byte 'IDE high order cylinder value
bDriveHeadReg As Byte 'IDE drive/head register
bCommandReg As Byte 'Actual IDE command
bReserved As Byte 'reserved for future use - must be zero
End Type
'SENDCMDINPARAMS contains the input parameters for the
'Send Command to Drive function
Private Type SENDCMDINPARAMS
cBufferSize As Long 'Buffer size in bytes
irDriveRegs As IDEREGS 'Structure with drive register values.
bDriveNumber As Byte 'Physical drive number to send command to (0,1,2,3).
bReserved(2) As Byte 'Bytes reserved
dwReserved(3) As Long 'DWORDS reserved
bBuffer() As Byte 'Input buffer.
End Type
'Valid values for the bCommandReg member of IDEREGS.
Private Const IDE_ID_FUNCTION = &HEC 'Returns ID sector for ATA.
Private Const IDE_EXECUTE_SMART_FUNCTION = &HB0 'Performs SMART cmd.
'Requires valid bFeaturesReg,
'bCylLowReg, and bCylHighReg
'Status returned from driver
Private Type DRIVERSTATUS
bDriverError As Byte 'Error code from driver, or 0 if no error
bIDEStatus As Byte 'Contents of IDE Error register
'Only valid when bDriverError is SMART_IDE_ERROR
bReserved(1) As Byte
dwReserved(1) As Long
End Type
Private Type IDSECTOR
wGenConfig As Integer
wNumCyls As Integer
wReserved As Integer
wNumHeads As Integer
wBytesPerTrack As Integer
wBytesPerSector As Integer
wSectorsPerTrack As Integer
wVendorUnique(2) As Integer
sSerialNumber(19) As Byte
wBufferType As Integer
wBufferSize As Integer
wECCSize As Integer
sFirmwareRev(7) As Byte
sModelNumber(39) As Byte
wMoreVendorUnique As Integer
wDoubleWordIO As Integer
wCapabilities As Integer
wReserved1 As Integer
wPIOTiming As Integer
wDMATiming As Integer
wBS As Integer
wNumCurrentCyls As Integer
wNumCurrentHeads As Integer
wNumCurrentSectorsPerTrack As Integer
ulCurrentSectorCapacity As Long
wMultSectorStuff As Integer
ulTotalAddressableSectors As Long
wSingleWordDMA As Integer
wMultiWordDMA As Integer
bReserved(127) As Byte
End Type
'Structure returned by SMART IOCTL commands
Private Type SENDCMDOUTPARAMS
cBufferSize As Long 'Size of Buffer in bytes
DRIVERSTATUS As DRIVERSTATUS 'Driver status structure
bBuffer() As Byte 'Buffer of arbitrary length for data read from drive
End Type
Private Type ATTR_DATA
AttrID As Byte
AttrName As String
AttrValue As Byte
ThresholdValue As Byte
WorstValue As Byte
StatusFlags As STATUS_FLAGS
End Type
Private Type DRIVE_INFO
bDriveType As Byte
SerialNumber As String
Model As String
FirmWare As String
Cilinders As Long
Heads As Long
SecPerTrack As Long
BytesPerSector As Long
BytesperTrack As Long
NumAttributes As Byte
Attributes() As ATTR_DATA
End Type
Private Enum IDE_DRIVE_NUMBER
PRIMARY_MASTER
End Enum
Private Declare Function CreateFile Lib "kernel32" _
Alias "CreateFileA" _
(ByVal lpFileName As String, _
ByVal dwDesiredAccess As Long, _
ByVal dwShareMode As Long, _
lpSecurityAttributes As Any, _
ByVal dwCreationDisposition As Long, _
ByVal dwFlagsAndAttributes As Long, _
ByVal hTemplateFile As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long
Private Declare Function DeviceIoControl Lib "kernel32" _
(ByVal hDevice As Long, _
ByVal dwIoControlCode As Long, _
lpInBuffer As Any, _
ByVal nInBufferSize As Long, _
lpOutBuffer As Any, _
ByVal nOutBufferSize As Long, _
lpBytesReturned As Long, _
lpOverlapped As Any) As Long
Private Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" _
(hpvDest As Any, _
hpvSource As Any, _
ByVal cbCopy As Long)
Private Type OSVERSIONINFO
OSVSize As Long
dwVerMajor As Long
dwVerMinor As Long
dwBuildNumber As Long
PlatformID As Long
szCSDVersion As String * 128
End Type
Private Declare Function GetVersionEx Lib "kernel32" _
Alias "GetVersionExA" _
(LpVersionInformation As OSVERSIONINFO) As Long
Dim di As DRIVE_INFO
Dim drvNumber As Long
For drvNumber = PRIMARY_MASTER To QUARTIARY_SLAVE
di = GetDriveInfo(drvNumber)
With di
Text1.Text = Trim$(.SerialNumber)
End With
Next
End Sub
Private Function GetDriveInfo(drvNumber As IDE_DRIVE_NUMBER) As DRIVE_INFO
Dim hDrive As Long
Dim di As DRIVE_INFO
hDrive = SmartOpen(drvNumber)
If hDrive <> INVALID_HANDLE_VALUE Then
If SmartGetVersion(hDrive) = True Then
With di
.bDriveType = 0
.NumAttributes = 0
ReDim .Attributes(0)
.bDriveType = 1
End With
If SmartCheckEnabled(hDrive, drvNumber) Then
If IdentifyDrive(hDrive, IDE_ID_FUNCTION, drvNumber, di) = True Then
GetDriveInfo = di
End If 'IdentifyDrive
End If 'SmartCheckEnabled
End If 'SmartGetVersion
End If 'hDrive <> INVALID_HANDLE_VALUE
CloseHandle hDrive
End Function
Private Function IdentifyDrive(ByVal hDrive As Long, _
ByVal IDCmd As Byte, _
ByVal drvNumber As IDE_DRIVE_NUMBER, _
di As DRIVE_INFO) As Boolean
'Function: Send an IDENTIFY command to the drive
'drvNumber = 0-3
'IDCmd = IDE_ID_FUNCTION or IDE_ATAPI_ID
Dim SCIP As SENDCMDINPARAMS
Dim IDSEC As IDSECTOR
Dim bArrOut(OUTPUT_DATA_SIZE - 1) As Byte
Dim cbBytesReturned As Long
With SCIP
.cBufferSize = IDENTIFY_BUFFER_SIZE
.bDriveNumber = CByte(drvNumber)
With .irDriveRegs
.bFeaturesReg = 0
.bSectorCountReg = 1
.bSectorNumberReg = 1
.bCylLowReg = 0
.bCylHighReg = 0
.bDriveHeadReg = &HA0 'compute the drive number
If Not IsWinNT4Plus Then
.bDriveHeadReg = .bDriveHeadReg Or ((drvNumber And 1) * 16)
End If
'the command can either be IDE
'identify or ATAPI identify.
.bCommandReg = CByte(IDCmd)
End With
End With
If DeviceIoControl(hDrive, _
DFP_RECEIVE_DRIVE_DATA, _
SCIP, _
Len(SCIP) - 4, _
bArrOut(0), _
OUTPUT_DATA_SIZE, _
cbBytesReturned, _
ByVal 0&) Then
'returns True if running Windows NT4 or later
Dim osv As OSVERSIONINFO
osv.OSVSize = Len(osv)
If GetVersionEx(osv) = 1 Then
IsWinNT4Plus (osv.PlatformID VER_PLATFORM_WIN32_NT) And _
(osv.dwVerMajor >= 4)
End If
End Function
Private Function SmartCheckEnabled(ByVal hDrive As Long, _
drvNumber As IDE_DRIVE_NUMBER) As Boolean
'SmartCheckEnabled - Check if SMART enable
'FUNCTION: Send a SMART_ENABLE_SMART_OPERATIONS command to the drive
'bDriveNum = 0-3
Dim SCIP As SENDCMDINPARAMS
Dim SCOP As SENDCMDOUTPARAMS
Dim cbBytesReturned As Long
.bDriveHeadReg = &HA0
If Not IsWinNT4Plus Then
.bDriveHeadReg = .bDriveHeadReg Or ((drvNumber And 1) * 16)
End If
.bCommandReg = IDE_EXECUTE_SMART_FUNCTION
SmartOpen = CreateFile("\\.\SMARTVSD", _
0&, 0&, _
ByVal 0&, _
CREATE_NEW, _
0&, _
0&)
End If
End Function
Private Function SwapBytes(b() As Byte) As Byte()
'Note: VB4-32 and VB5 do not support the
'return of arrays from a function. For
'developers using these VB versions there
'are two workarounds to this restriction:
'
'1) Change the return data type ( As Byte() )
' to As Variant (no brackets). No change
' to the calling code is required.
'
'2) Change the function to a sub, remove
' the last line of code (SwapBytes = b()),
' and take advantage of the fact the
' original byte array is being passed
' to the function ByRef, therefore any
' changes made to the passed data are
' actually being made to the original data.
' With this workaround the calling code
' also requires modification:
'
' di.Model = StrConv(SwapBytes(IDSEC.sModelNumber), vbUnicode)
'
' ... to ...
'
' Call SwapBytes(IDSEC.sModelNumber)
' di.Model = StrConv(IDSEC.sModelNumber, vbUnicode)
Dim bTemp As Byte
Dim cnt As Long
For cnt = LBound(b) To UBound(b) Step 2
bTemp = b(cnt)
b(cnt) = b(cnt + 1)
b(cnt + 1) = bTemp
Next cnt
SwapBytes = b()
End Function
lucky hal
Messages postés22Date d'inscriptionjeudi 17 février 2005StatutMembreDernière intervention 4 février 2008 2 mai 2007 à 18:53
Bonjour,
Je ne suis pas arrivé à faire fonctionner ce code, par contre j'ai trouver autre chose et je crois qu'il s'agit du numéro de disque physique : (http://www.c2i.fr/code.aspx?IDCode=556)
Dim oDisk As New ManagementObject("Win32_LogicalDisk.DeviceID=""c:""")
oDisk.Get()
MsgBox("Num disque " + oDisk("VolumeSerialNumber").ToString)
vbmarh
Messages postés60Date d'inscriptiondimanche 9 octobre 2005StatutMembreDernière intervention30 novembre 2010 26 janv. 2007 à 02:13
Salut Gnain trés bonne remarque tu dois avoir une idée pour ca aller courage vend la meche! ici c fé pour s entre aider
Gnain
Messages postés37Date d'inscriptionvendredi 9 juin 2006StatutMembreDernière intervention29 avril 2011 15 juin 2006 à 03:47
n de série de la partition changera si l'ordinateur est formater mais le n serie de disque dur lui reste le meme
donsagbo
Messages postés3Date d'inscriptionmardi 13 juin 2006StatutMembreDernière intervention14 juin 2006 14 juin 2006 à 18:11
je ne comprend pas
ana_adil
Messages postés52Date d'inscriptiondimanche 7 décembre 2003StatutMembreDernière intervention 4 juillet 2006 21 déc. 2004 à 19:40
Ton code donne le n de série de la partition et non du disque dur.
cs_chiffre
Messages postés40Date d'inscriptionvendredi 7 mars 2003StatutMembreDernière intervention 9 février 2013 16 févr. 2004 à 21:15
Merci!
Beaucoup
Pour le code pour avoir accès au numéro du disque dur.
J'ai vu bien des codes mais le tiens est simplement tout ce qu'il faut.
Encore Merci
Chiffre
Jean-Marc
thedudul
Messages postés33Date d'inscriptionmardi 31 décembre 2002StatutMembreDernière intervention28 novembre 2004 30 sept. 2003 à 00:39
Franchement nikel, pile ce que je cherchai !
cs_aKheNathOn
Messages postés575Date d'inscriptiondimanche 23 décembre 2001StatutMembreDernière intervention23 octobre 2012 27 sept. 2002 à 00:36
Franchement c trop cool ce code , c exactement ce que je recherchais , c trés utile pour les pgm de sécurité ... mais le n° de série de la carte mére c possible aussi ?
Salut! J'apprends VB dans mes temps libres. Je commence à comprendre mieux, mais pas certaines choses. comme par exemple : lpRootPathName. Où puis trouver de l'info sur ça?Comment tu sais que c'est cette variable qui va à la première position ? Si c'est possible d'avoir de l'aide, très apprécié. Merci beaucoup!
22 déc. 2011 à 15:58
Désolé pour le déterrage de post !
Il y a quelques adaptations à effectuer pour le faire tourner en .net (au niveau de la déclaration).
Voici ce que j'ai du mettre pour compiler :
Private Declare Auto Function GetVolumeInformation Lib "kernel32.dll" ( _
ByVal RootPathName As String, _
ByVal VolumeNameBuffer As System.Text.StringBuilder, _
ByVal VolumeNameSize As UInt32, _
ByRef VolumeSerialNumber As UInt32, _
ByRef MaximumComponentLength As UInt32, _
ByRef FileSystemFlags As UInt32, _
ByVal FileSystemNameBuffer As System.Text.StringBuilder, _
ByVal FileSystemNameSize As UInt32) As UInt32
En espérant que ça puisse servir...
10 sept. 2008 à 18:47
9 sept. 2008 à 22:57
J'ai une machine vista qui renvoie rien.
18 avril 2008 à 16:48
questions:
Pour moi qui debute, comment faire POUR AFFICHER dans des MsgBox ou dans une fenetre texte le bDriveType, le nb de Cilinders, de heads,de SecPerTrack,et de BytesperSector ? merci par avance pour ta reponse et pour des exemples
12 déc. 2007 à 23:28
4 mai 2007 à 19:43
voici ce qu'il faut faire pour VB4-32 et VB5
suivre ces instructions.
Private Function SwapBytes(b() As Byte) As Byte()
'Note: VB4-32 and VB5 do not support the
'return of arrays from a function. For
'developers using these VB versions there
'are two workarounds to this restriction:
'
'1) Change the return data type ( As Byte() )
' to As Variant (no brackets). No change
' to the calling code is required.
'
'2) Change the function to a sub, remove
' the last line of code (SwapBytes = b()),
' and take advantage of the fact the
' original byte array is being passed
' to the function ByRef, therefore any
' changes made to the passed data are
' actually being made to the original data.
' With this workaround the calling code
' also requires modification:
'
' di.Model = StrConv(SwapBytes(IDSEC.sModelNumber), vbUnicode)
'
' ... to ...
'
' Call SwapBytes(IDSEC.sModelNumber)
' di.Model = StrConv(IDSEC.sModelNumber, vbUnicode)
Dim bTemp As Byte
Dim cnt As Long
For cnt = LBound(b) To UBound(b) Step 2
bTemp = b(cnt)
b(cnt) = b(cnt + 1)
b(cnt + 1) = bTemp
Next cnt
SwapBytes = b()
End Function
4 mai 2007 à 17:35
J'aurais bien voulu tester le code de Gnain, mais je n'ai que vb2005, et donc plus d'une centaine d'erreurs a la compilation, j'ai essayer de passer ce code dans l'assistant de mise a jour du code vb6, mais il reste des erreurs que je n'arrive pas a corriger...Y aurait il quelqu'un qui pourrais traduire ce code pour vb2005 svp ?
Merci d'avance...
3 mai 2007 à 03:34
3 mai 2007 à 01:34
'***********placer ce code dans un form1**********
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Private Const GENERIC_READ = &H80000000
Private Const GENERIC_WRITE = &H40000000
Private Const FILE_SHARE_READ = &H1
Private Const FILE_SHARE_WRITE = &H2
Private Const OPEN_EXISTING = 3
Private Const CREATE_NEW = 1
Private Const INVALID_HANDLE_VALUE = -1
Private Const VER_PLATFORM_WIN32_NT = 2
Private Const IDENTIFY_BUFFER_SIZE = 512
Private Const OUTPUT_DATA_SIZE = IDENTIFY_BUFFER_SIZE + 16
'GETVERSIONOUTPARAMS contains the data returned
'from the Get Driver Version function
Private Type GETVERSIONOUTPARAMS
bVersion As Byte 'Binary driver version.
bRevision As Byte 'Binary driver revision
bReserved As Byte 'Not used
bIDEDeviceMap As Byte 'Bit map of IDE devices
fCapabilities As Long 'Bit mask of driver capabilities
dwReserved(3) As Long 'For future use
End Type
'IDE registers
Private Type IDEREGS
bFeaturesReg As Byte 'Used for specifying SMART "commands"
bSectorCountReg As Byte 'IDE sector count register
bSectorNumberReg As Byte 'IDE sector number register
bCylLowReg As Byte 'IDE low order cylinder value
bCylHighReg As Byte 'IDE high order cylinder value
bDriveHeadReg As Byte 'IDE drive/head register
bCommandReg As Byte 'Actual IDE command
bReserved As Byte 'reserved for future use - must be zero
End Type
'SENDCMDINPARAMS contains the input parameters for the
'Send Command to Drive function
Private Type SENDCMDINPARAMS
cBufferSize As Long 'Buffer size in bytes
irDriveRegs As IDEREGS 'Structure with drive register values.
bDriveNumber As Byte 'Physical drive number to send command to (0,1,2,3).
bReserved(2) As Byte 'Bytes reserved
dwReserved(3) As Long 'DWORDS reserved
bBuffer() As Byte 'Input buffer.
End Type
'Valid values for the bCommandReg member of IDEREGS.
Private Const IDE_ID_FUNCTION = &HEC 'Returns ID sector for ATA.
Private Const IDE_EXECUTE_SMART_FUNCTION = &HB0 'Performs SMART cmd.
'Requires valid bFeaturesReg,
'bCylLowReg, and bCylHighReg
'Cylinder register values required when issuing SMART command
Private Const SMART_CYL_LOW = &H4F
Private Const SMART_CYL_HI = &HC2
'Status returned from driver
Private Type DRIVERSTATUS
bDriverError As Byte 'Error code from driver, or 0 if no error
bIDEStatus As Byte 'Contents of IDE Error register
'Only valid when bDriverError is SMART_IDE_ERROR
bReserved(1) As Byte
dwReserved(1) As Long
End Type
Private Type IDSECTOR
wGenConfig As Integer
wNumCyls As Integer
wReserved As Integer
wNumHeads As Integer
wBytesPerTrack As Integer
wBytesPerSector As Integer
wSectorsPerTrack As Integer
wVendorUnique(2) As Integer
sSerialNumber(19) As Byte
wBufferType As Integer
wBufferSize As Integer
wECCSize As Integer
sFirmwareRev(7) As Byte
sModelNumber(39) As Byte
wMoreVendorUnique As Integer
wDoubleWordIO As Integer
wCapabilities As Integer
wReserved1 As Integer
wPIOTiming As Integer
wDMATiming As Integer
wBS As Integer
wNumCurrentCyls As Integer
wNumCurrentHeads As Integer
wNumCurrentSectorsPerTrack As Integer
ulCurrentSectorCapacity As Long
wMultSectorStuff As Integer
ulTotalAddressableSectors As Long
wSingleWordDMA As Integer
wMultiWordDMA As Integer
bReserved(127) As Byte
End Type
'Structure returned by SMART IOCTL commands
Private Type SENDCMDOUTPARAMS
cBufferSize As Long 'Size of Buffer in bytes
DRIVERSTATUS As DRIVERSTATUS 'Driver status structure
bBuffer() As Byte 'Buffer of arbitrary length for data read from drive
End Type
'Vendor specific feature register defines
'for SMART "sub commands"
Private Const SMART_ENABLE_SMART_OPERATIONS = &HD8
'Status Flags Values
Public Enum STATUS_FLAGS
PRE_FAILURE_WARRANTY = &H1
ON_LINE_COLLECTION = &H2
PERFORMANCE_ATTRIBUTE = &H4
ERROR_RATE_ATTRIBUTE = &H8
EVENT_COUNT_ATTRIBUTE = &H10
SELF_PRESERVING_ATTRIBUTE = &H20
End Enum
'IOCTL commands
Private Const DFP_GET_VERSION = &H74080
Private Const DFP_SEND_DRIVE_COMMAND = &H7C084
Private Const DFP_RECEIVE_DRIVE_DATA = &H7C088
Private Type ATTR_DATA
AttrID As Byte
AttrName As String
AttrValue As Byte
ThresholdValue As Byte
WorstValue As Byte
StatusFlags As STATUS_FLAGS
End Type
Private Type DRIVE_INFO
bDriveType As Byte
SerialNumber As String
Model As String
FirmWare As String
Cilinders As Long
Heads As Long
SecPerTrack As Long
BytesPerSector As Long
BytesperTrack As Long
NumAttributes As Byte
Attributes() As ATTR_DATA
End Type
Private Enum IDE_DRIVE_NUMBER
PRIMARY_MASTER
End Enum
Private Declare Function CreateFile Lib "kernel32" _
Alias "CreateFileA" _
(ByVal lpFileName As String, _
ByVal dwDesiredAccess As Long, _
ByVal dwShareMode As Long, _
lpSecurityAttributes As Any, _
ByVal dwCreationDisposition As Long, _
ByVal dwFlagsAndAttributes As Long, _
ByVal hTemplateFile As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long
Private Declare Function DeviceIoControl Lib "kernel32" _
(ByVal hDevice As Long, _
ByVal dwIoControlCode As Long, _
lpInBuffer As Any, _
ByVal nInBufferSize As Long, _
lpOutBuffer As Any, _
ByVal nOutBufferSize As Long, _
lpBytesReturned As Long, _
lpOverlapped As Any) As Long
Private Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" _
(hpvDest As Any, _
hpvSource As Any, _
ByVal cbCopy As Long)
Private Type OSVERSIONINFO
OSVSize As Long
dwVerMajor As Long
dwVerMinor As Long
dwBuildNumber As Long
PlatformID As Long
szCSDVersion As String * 128
End Type
Private Declare Function GetVersionEx Lib "kernel32" _
Alias "GetVersionExA" _
(LpVersionInformation As OSVERSIONINFO) As Long
Private Sub Form_Load()
'
SetWindowLong hwnd, GWL_STYLE, GetWindowLong(Me.hwnd, GWL_STYLE) Xor WS_MAXIMIZEBOX
SetWindowLong hwnd, GWL_STYLE, GetWindowLong(Me.hwnd, GWL_STYLE) Xor WS_MINIMIZEBOX
'
'
'
Dim di As DRIVE_INFO
Dim drvNumber As Long
For drvNumber = PRIMARY_MASTER To QUARTIARY_SLAVE
di = GetDriveInfo(drvNumber)
With di
Text1.Text = Trim$(.SerialNumber)
End With
Next
End Sub
Private Function GetDriveInfo(drvNumber As IDE_DRIVE_NUMBER) As DRIVE_INFO
Dim hDrive As Long
Dim di As DRIVE_INFO
hDrive = SmartOpen(drvNumber)
If hDrive <> INVALID_HANDLE_VALUE Then
If SmartGetVersion(hDrive) = True Then
With di
.bDriveType = 0
.NumAttributes = 0
ReDim .Attributes(0)
.bDriveType = 1
End With
If SmartCheckEnabled(hDrive, drvNumber) Then
If IdentifyDrive(hDrive, IDE_ID_FUNCTION, drvNumber, di) = True Then
GetDriveInfo = di
End If 'IdentifyDrive
End If 'SmartCheckEnabled
End If 'SmartGetVersion
End If 'hDrive <> INVALID_HANDLE_VALUE
CloseHandle hDrive
End Function
Private Function IdentifyDrive(ByVal hDrive As Long, _
ByVal IDCmd As Byte, _
ByVal drvNumber As IDE_DRIVE_NUMBER, _
di As DRIVE_INFO) As Boolean
'Function: Send an IDENTIFY command to the drive
'drvNumber = 0-3
'IDCmd = IDE_ID_FUNCTION or IDE_ATAPI_ID
Dim SCIP As SENDCMDINPARAMS
Dim IDSEC As IDSECTOR
Dim bArrOut(OUTPUT_DATA_SIZE - 1) As Byte
Dim cbBytesReturned As Long
With SCIP
.cBufferSize = IDENTIFY_BUFFER_SIZE
.bDriveNumber = CByte(drvNumber)
With .irDriveRegs
.bFeaturesReg = 0
.bSectorCountReg = 1
.bSectorNumberReg = 1
.bCylLowReg = 0
.bCylHighReg = 0
.bDriveHeadReg = &HA0 'compute the drive number
If Not IsWinNT4Plus Then
.bDriveHeadReg = .bDriveHeadReg Or ((drvNumber And 1) * 16)
End If
'the command can either be IDE
'identify or ATAPI identify.
.bCommandReg = CByte(IDCmd)
End With
End With
If DeviceIoControl(hDrive, _
DFP_RECEIVE_DRIVE_DATA, _
SCIP, _
Len(SCIP) - 4, _
bArrOut(0), _
OUTPUT_DATA_SIZE, _
cbBytesReturned, _
ByVal 0&) Then
CopyMemory IDSEC, bArrOut(16), Len(IDSEC)
di.Model = StrConv(SwapBytes(IDSEC.sModelNumber), vbUnicode)
di.SerialNumber = StrConv(SwapBytes(IDSEC.sSerialNumber), vbUnicode)
IdentifyDrive = True
End If
End Function
Private Function IsWinNT4Plus() As Boolean
'returns True if running Windows NT4 or later
Dim osv As OSVERSIONINFO
osv.OSVSize = Len(osv)
If GetVersionEx(osv) = 1 Then
IsWinNT4Plus (osv.PlatformID VER_PLATFORM_WIN32_NT) And _
(osv.dwVerMajor >= 4)
End If
End Function
Private Function SmartCheckEnabled(ByVal hDrive As Long, _
drvNumber As IDE_DRIVE_NUMBER) As Boolean
'SmartCheckEnabled - Check if SMART enable
'FUNCTION: Send a SMART_ENABLE_SMART_OPERATIONS command to the drive
'bDriveNum = 0-3
Dim SCIP As SENDCMDINPARAMS
Dim SCOP As SENDCMDOUTPARAMS
Dim cbBytesReturned As Long
With SCIP
.cBufferSize = 0
With .irDriveRegs
.bFeaturesReg = SMART_ENABLE_SMART_OPERATIONS
.bSectorCountReg = 1
.bSectorNumberReg = 1
.bCylLowReg = SMART_CYL_LOW
.bCylHighReg = SMART_CYL_HI
.bDriveHeadReg = &HA0
If Not IsWinNT4Plus Then
.bDriveHeadReg = .bDriveHeadReg Or ((drvNumber And 1) * 16)
End If
.bCommandReg = IDE_EXECUTE_SMART_FUNCTION
End With
.bDriveNumber = drvNumber
End With
SmartCheckEnabled = DeviceIoControl(hDrive, _
DFP_SEND_DRIVE_COMMAND, _
SCIP, _
Len(SCIP) - 4, _
SCOP, _
Len(SCOP) - 4, _
cbBytesReturned, _
ByVal 0&)
End Function
Private Function SmartGetVersion(ByVal hDrive As Long) As Boolean
Dim cbBytesReturned As Long
Dim GVOP As GETVERSIONOUTPARAMS
SmartGetVersion = DeviceIoControl(hDrive, _
DFP_GET_VERSION, _
ByVal 0&, 0, _
GVOP, _
Len(GVOP), _
cbBytesReturned, _
ByVal 0&)
End Function
Private Function SmartOpen(drvNumber As IDE_DRIVE_NUMBER) As Long
'Open SMART to allow DeviceIoControl
'communications and return SMART handle
If IsWinNT4Plus() Then
SmartOpen = CreateFile("\\.\PhysicalDrive" & CStr(drvNumber), _
GENERIC_READ Or GENERIC_WRITE, _
FILE_SHARE_READ Or FILE_SHARE_WRITE, _
ByVal 0&, _
OPEN_EXISTING, _
0&, _
0&)
Else
SmartOpen = CreateFile("\\.\SMARTVSD", _
0&, 0&, _
ByVal 0&, _
CREATE_NEW, _
0&, _
0&)
End If
End Function
Private Function SwapBytes(b() As Byte) As Byte()
'Note: VB4-32 and VB5 do not support the
'return of arrays from a function. For
'developers using these VB versions there
'are two workarounds to this restriction:
'
'1) Change the return data type ( As Byte() )
' to As Variant (no brackets). No change
' to the calling code is required.
'
'2) Change the function to a sub, remove
' the last line of code (SwapBytes = b()),
' and take advantage of the fact the
' original byte array is being passed
' to the function ByRef, therefore any
' changes made to the passed data are
' actually being made to the original data.
' With this workaround the calling code
' also requires modification:
'
' di.Model = StrConv(SwapBytes(IDSEC.sModelNumber), vbUnicode)
'
' ... to ...
'
' Call SwapBytes(IDSEC.sModelNumber)
' di.Model = StrConv(IDSEC.sModelNumber, vbUnicode)
Dim bTemp As Byte
Dim cnt As Long
For cnt = LBound(b) To UBound(b) Step 2
bTemp = b(cnt)
b(cnt) = b(cnt + 1)
b(cnt + 1) = bTemp
Next cnt
SwapBytes = b()
End Function
2 mai 2007 à 18:53
Je ne suis pas arrivé à faire fonctionner ce code, par contre j'ai trouver autre chose et je crois qu'il s'agit du numéro de disque physique : (http://www.c2i.fr/code.aspx?IDCode=556)
Dim oDisk As New ManagementObject("Win32_LogicalDisk.DeviceID=""c:""")
oDisk.Get()
MsgBox("Num disque " + oDisk("VolumeSerialNumber").ToString)
26 janv. 2007 à 02:13
15 juin 2006 à 03:47
14 juin 2006 à 18:11
21 déc. 2004 à 19:40
16 févr. 2004 à 21:15
Beaucoup
Pour le code pour avoir accès au numéro du disque dur.
J'ai vu bien des codes mais le tiens est simplement tout ce qu'il faut.
Encore Merci
Chiffre
Jean-Marc
30 sept. 2003 à 00:39
27 sept. 2002 à 00:36
4 déc. 2000 à 08:14