- 最後登錄
- 2024-5-22
- 在線時間
- 0 小時
- 註冊時間
- 2007-5-12
- 閱讀權限
- 70
- 精華
- 0
- UID
- 1286899
- 帖子
- 1412
- 積分
- 17880 點
- 潛水值
- 38467 米
| 分享使你變得更實在,可以使其他人感到快樂,分享是我們的動力。今天就來分享你的資訊、圖片或檔案吧。 我的技術(到處查)只能到這邊
是沒有出錯,但是 值 就是沒法 跟 vb6 一樣出的來
有些有多餘的程式碼 妳可以斟酌刪除- Public Class Form1
- Public Structure IDEREGS
- Dim bFeaturesReg As Byte
- Dim bSectorCountReg As Byte
- Dim bSectorNumberReg As Byte
- Dim bCylLowReg As Byte
- Dim bCylHighReg As Byte
- Dim bDriveHeadReg As Byte
- Dim bCommandReg As Byte
- Dim bReserved As Byte
- End Structure
- Public Structure DRIVERSTATUS
- Dim bDriveError As Byte
- Dim bIDEStatus As Byte
- <VBFixedArray(2)> Public bReserved As Byte
- <VBFixedArray(2)> Public dwReserved As Integer
- End Structure
- Public Structure SENDCMDOUTPARAMS
- Dim cBufferSize As Integer
- Dim DStatus As DRIVERSTATUS
- <VBFixedArray(512)> Public bBuffer As Byte
- End Structure
- Public Structure SENDCMDINPARAMS
- Dim cBufferSize As Integer
- Dim irDriveRegs As IDEREGS
- Dim bDriveNumber As Byte
- <VBFixedArray(3)> Public bReserved As Byte
- <VBFixedArray(4)> Public dwReserved As Integer
- End Structure
- 'API宣告
- Private Declare Function CreateFileA Lib "Kernel32" (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 Declare Sub RtlZeroMemory Lib "Kernel32" Alias "RtlZeroMemory" (ByVal dest As SENDCMDINPARAMS, ByVal numBytes As Integer)
- Private Declare Sub RtlZeroMemory Lib "Kernel32" Alias "RtlZeroMemory" (ByVal dest As SENDCMDOUTPARAMS, ByVal numBytes As Integer)
- Private Declare Function DeviceIoControl Lib "Kernel32" _
- (ByVal hDevice As Integer, _
- ByVal dwIoControlCode As Integer, _
- ByVal lpInBuffer As SENDCMDINPARAMS, _
- ByVal nInBufferSize As SENDCMDINPARAMS, _
- ByVal lpOutBuffer As SENDCMDOUTPARAMS, _
- ByVal nOutBufferSize As SENDCMDOUTPARAMS, _
- ByVal lpBytesReturned As Integer, _
- ByVal lpOverlapped As Integer) As Integer
- Private Declare Function DeviceIoControl Lib "Kernel32" _
- (ByVal hDevice As Integer, _
- ByVal dwIoControlCode As Integer, _
- ByRef lpInBuffer As SENDCMDINPARAMS, _
- ByVal nInBufferSize As Integer, _
- ByRef lpOutBuffer As SENDCMDOUTPARAMS, _
- ByVal nOutBufferSize As Integer, _
- ByVal lpBytesReturned As Integer, _
- ByVal lpOverlapped As Integer) As Integer
- Private Declare Function CloseHandle Lib "Kernel32" _
- (ByVal hObject As Integer) As Integer
- Private Declare Sub RtlMoveMemory Lib "Kernel32" _
- (ByVal Destination As IntPtr, ByVal Source As IntPtr, ByVal Length As Integer)
- ' 取得硬碟序號
- Private Function Get_HD_SNo(ByVal DrvIdx As Byte) As String
- Dim ParaIn As SENDCMDINPARAMS
- Dim ParaOut As SENDCMDOUTPARAMS
- Dim ParaIn1() As SENDCMDINPARAMS
- Dim ParaOut1() As SENDCMDOUTPARAMS
- 'Dim ParaIn As New SENDCMDINPARAMS
- 'Dim ParaOut As New SENDCMDOUTPARAMS
- Dim Sno As String
- Dim h As Integer
- Dim intLp As Integer
- If Len(Environ("OS")) > 0 Then
- h = CreateFileA("\\.\PhysicalDrive" & DrvIdx, -1073741824, 3, 0, 3, 0, 0)
- Else
- h = CreateFileA("\\.\Smartvsd", 0, 0, 0, 1, 0, 0)
- End If
- If h = 0 Then
- Exit Function
- End If
- RtlZeroMemory(ParaIn, Len(ParaIn))
- RtlZeroMemory(ParaOut, Len(ParaOut))
- With ParaIn
- .bDriveNumber = DrvIdx
- .cBufferSize = 512
- With .irDriveRegs
- .bDriveHeadReg = IIf(DrvIdx And 1, 176, 160)
- .bCommandReg = 236
- .bSectorCountReg = 1
- .bSectorNumberReg = 1
- End With
- End With
- DeviceIoControl(h, 508040, ParaIn, Len(ParaIn), ParaOut, Len(ParaOut), 0, 0)
- 'For intLp = 21 To 40 Step 2
- 'If ParaOut.bBuffer(intLp + 1) = 0 Then Exit For
- 'Sno = Sno & Chr(ParaOut.bBuffer(intLp + 1))
- 'If ParaOut.bBuffer(intLp) > 0 Then Sno = Sno & Chr(ParaOut.bBuffer(intLp))
- 'Next
- Dim tmp As Integer
- For intLp = 21 To 40 Step 2
- tmp = intLp + 1
- ReDim Preserve ParaOut1(0 To 511)
- ParaOut.bBuffer = tmp
- Sno &= Chr(ParaOut.bBuffer)
- Next
- tmp = Byte.Parse(21)
- 'ParaOut.bBuffer = 1
- CloseHandle(h)
- Get_HD_SNo = Trim(Sno)
- End Function
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- MsgBox("硬碟序號 : " & Get_HD_SNo(0)) ' 第一顆硬碟.
- End Sub
- Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
- Dim xxxxx
- For intLp = 21 To 40 Step 2
- xxxxx &= Chr(intLp)
- Next
- MsgBox(xxxxx)
- End Sub
- End Class
複製代碼 ... |
|