我找到了!这是等效的VB.NET代码.它不完全是VB6代码的转换版本,但做同样的事情.请享用!
Public Class HDDInfo #Region " Declatrations " Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Integer, ByVal dwShareMode As Integer, ByVal lpSecurityAttributes As Integer, ByVal dwCreationDisposition As Integer, ByVal dwFlagsAndAttributes As Integer, ByVal hTemplateFile As Integer) As Integer_ Private Shared Function CloseHandle(ByVal hObject As Integer) As Integer End Function _ Private Shared Function DeviceIoControl(ByVal hDevice As Integer, ByVal dwIoControlCode As Integer, <[In](), Out()> ByVal lpInBuffer As SENDCMDINPARAMS, ByVal lpInBufferSize As Integer, <[In](), Out()> ByVal lpOutBuffer As SENDCMDOUTPARAMS, ByVal lpOutBufferSize As Integer, _ ByRef lpBytesReturned As Integer, ByVal lpOverlapped As Integer) As Integer End Function Private Const FILE_SHARE_READ As Short = &H1 Private Const FILE_SHARE_WRITE As Short = &H2 Private Const GENERIC_READ As Integer = &H80000000 Private Const GENERIC_WRITE As Integer = &H40000000 Private Const OPEN_EXISTING As Short = 3 Private Const CREATE_NEW As Short = 1 Private Const VER_PLATFORM_WIN32_NT As Integer = 2 Private Const DFP_RECEIVE_DRIVE_DATA As Integer = &H7C088 Private Const INVALID_HANDLE_VALUE As Integer = -1 #End Region #Region " Classes " _ Private Class IDEREGS Public Features As Byte Public SectorCount As Byte Public SectorNumber As Byte Public CylinderLow As Byte Public CylinderHigh As Byte Public DriveHead As Byte Public Command As Byte Public Reserved As Byte End Class _ Private Class SENDCMDINPARAMS Public BufferSize As Integer Public DriveRegs As IDEREGS Public DriveNumber As Byte _ Public Reserved As Byte() _ Public Reserved2 As Integer() Public Sub New() DriveRegs = New IDEREGS() Reserved = New Byte(2) {} Reserved2 = New Integer(3) {} End Sub End Class _ Private Class DRIVERSTATUS Public DriveError As Byte Public IDEStatus As Byte _ Public Reserved As Byte() _ Public Reserved2 As Integer() Public Sub New() Reserved = New Byte(1) {} Reserved2 = New Integer(1) {} End Sub End Class _ Private Class IDSECTOR Public GenConfig As Short Public NumberCylinders As Short Public Reserved As Short Public NumberHeads As Short Public BytesPerTrack As Short Public BytesPerSector As Short Public SectorsPerTrack As Short _ Public VendorUnique As Short() _ Public SerialNumber As Char() Public BufferClass As Short Public BufferSize As Short Public ECCSize As Short _ Public FirmwareRevision As Char() _ Public ModelNumber As Char() Public MoreVendorUnique As Short Public DoubleWordIO As Short Public Capabilities As Short Public Reserved1 As Short Public PIOTiming As Short Public DMATiming As Short Public BS As Short Public NumberCurrentCyls As Short Public NumberCurrentHeads As Short Public NumberCurrentSectorsPerTrack As Short Public CurrentSectorCapacity As Integer Public MultipleSectorCapacity As Short Public MultipleSectorStuff As Short Public TotalAddressableSectors As Integer Public SingleWordDMA As Short Public MultiWordDMA As Short _ Public Reserved2 As Byte() End Class _ Private Class SENDCMDOUTPARAMS Public BufferSize As Integer Public Status As DRIVERSTATUS Public IDS As IDSECTOR Public Sub New() Status = New DRIVERSTATUS() IDS = New IDSECTOR() End Sub End Class #End Region #Region " Methods and Functions " Private Shared Function SwapChars(ByVal chars As Char()) As String For i As Integer = 0 To chars.Length - 2 Step 2 Dim t As Char t = chars(i) chars(i) = chars(i + 1) chars(i + 1) = t Next Dim s As New String(chars) Return s End Function Public Shared Function GetHDDInfoString() As String Dim serialNumber As String = " ", model As String = " ", firmware As String = " " Dim handle As Integer, returnSize As Integer = 0 Dim driveNumber As Integer = 0 Dim sci As New SENDCMDINPARAMS() Dim sco As New SENDCMDOUTPARAMS() If Environment.OSVersion.Platform = PlatformID.Win32NT Then handle = CreateFile("\\.\PhysicalDrive" & "0", GENERIC_READ + GENERIC_WRITE, FILE_SHARE_READ + FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0) Else handle = CreateFile("\\.\Smartvsd", 0, 0, 0, CREATE_NEW, 0, 0) End If If handle <> INVALID_HANDLE_VALUE Then sci.DriveNumber = CByte(driveNumber) sci.BufferSize = Marshal.SizeOf(sco) sci.DriveRegs.DriveHead = CByte((&HA0 Or driveNumber << 4)) sci.DriveRegs.Command = &HEC sci.DriveRegs.SectorCount = 1 sci.DriveRegs.SectorNumber = 1 If DeviceIoControl(handle, DFP_RECEIVE_DRIVE_DATA, sci, Marshal.SizeOf(sci), sco, Marshal.SizeOf(sco), _ returnSize, 0) <> 0 Then serialNumber = SwapChars(sco.IDS.SerialNumber) model = SwapChars(sco.IDS.ModelNumber) firmware = SwapChars(sco.IDS.FirmwareRevision) End If CloseHandle(handle) End If Return model.Trim & " " & serialNumber.Trim End Function #End Region End Class