找回密碼 或 安全提問
 註冊
|註冊|登錄

伊莉討論區

搜索
請尊重及感激所有版主付出和奉獻尊貴會員無限使用任何功能尊貴會員無限觀看附件圖片
mg無修上原亞衣259luxumgphotosho
雪屋温泉デスゾー全球靈卡ブタゴン回到相親原來是美帝國

休閒聊天興趣交流學術文化旅遊交流飲食交流家庭事務PC GAMETV GAME
熱門線上其他線上感情感性寵物交流家族門派動漫交流貼圖分享BL/GL
音樂世界影視娛樂女性頻道潮流資訊BT下載區GB下載區下載分享短片
電腦資訊數碼產品手機交流交易廣場網站事務長篇小說體育運動時事經濟
上班一族博彩娛樂

[繁]魔法科高中的劣等

高雄苓雅復興二路與四

[繁]老夫老妻重返青春

[繁]無職轉生 第二季1

吃冰嗎

[簡]單人房、日照一般
C & C++ 語言C# 語言Visual Basic 語言PHP 語言JAVA 語言
查看: 3167|回復: 6
打印上一主題下一主題

[求助]硬碟機器碼查詢 vb6轉2010[複製鏈接]

火土水風 該用戶已被刪除
跳轉到指定樓層
樓主
發表於 2012-6-27 07:32 PM|只看該作者|倒序瀏覽
本帖最後由 火土水風 於 2012-6-27 07:32 PM 編輯

vb6硬碟機器碼轉vb2010 頻頻出問題...請高手幫忙轉換@@
ps我知道網路上也有硬碟序號碼(vb.net) 但"查詢"並不是下面這種...
vb6硬碟機器碼查詢源碼如下:
  1. Private Type IDEREGS
  2.     bFeaturesReg As Byte
  3.     bSectorCountReg As Byte
  4.     bSectorNumberReg As Byte
  5.     bCylLowReg As Byte
  6.     bCylHighReg As Byte
  7.     bDriveHeadReg As Byte
  8.     bCommandReg As Byte
  9.     bReserved As Byte
  10. End Type

  11. Private Type DRIVERSTATUS
  12.     bDriveError As Byte
  13.     bIDEStatus As Byte
  14.     bReserved(1 To 2) As Byte
  15.     dwReserved(1 To 2) As Long
  16. End Type

  17. Private Type SENDCMDOUTPARAMS
  18.     cBufferSize As Long
  19.     DStatus As DRIVERSTATUS
  20.     bBuffer(1 To 512) As Byte
  21. End Type

  22. Private Type SENDCMDINPARAMS
  23.     cBufferSize As Long
  24.     irDriveRegs As IDEREGS
  25.     bDriveNumber As Byte
  26.     bReserved(1 To 3) As Byte
  27.     dwReserved(1 To 4) As Long
  28. End Type

  29. 'API宣告
  30. Private Declare Function CreateFileA Lib "Kernel32" _
  31.     (ByVal lpFileName As String, _
  32.     ByVal dwDesiredAccess As Long, _
  33.     ByVal dwShareMode As Long, _
  34.     ByVal lpSecurityAttributes As Long, _
  35.     ByVal dwCreationDisposition As Long, _
  36.     ByVal dwFlagsAndAttributes As Long, _
  37.     ByVal hTemplateFile As Long) As Long

  38. Private Declare Sub RtlZeroMemory Lib "Kernel32" _
  39.     (dest As Any, ByVal numBytes As Long)
  40.    
  41. Private Declare Function DeviceIoControl Lib "Kernel32" _
  42.     (ByVal hDevice As Long, _
  43.     ByVal dwIoControlCode As Long, _
  44.     lpInBuffer As Any, _
  45.     ByVal nInBufferSize As Long, _
  46.     lpOutBuffer As Any, _
  47.     ByVal nOutBufferSize As Long, _
  48.     lpBytesReturned As Long, _
  49.     ByVal lpOverlapped As Long) As Long

  50. Private Declare Function CloseHandle Lib "Kernel32" _
  51.     (ByVal hObject As Long) As Long
  52.    
  53.    
  54. Private Declare Sub RtlMoveMemory Lib "Kernel32" _
  55.     (Destination As Any, Source As Any, ByVal Length As Long)

  56. Private Sub Command1_Click()
  57.     MsgBox "硬碟序號 : " & Get_HD_SNo(0) ' 第一顆硬碟.
  58. End Sub

  59. ' 取得硬碟序號
  60. Private Function Get_HD_SNo(DrvIdx As Byte) As String
  61.    
  62.     Dim ParaIn As SENDCMDINPARAMS
  63.     Dim ParaOut As SENDCMDOUTPARAMS
  64.     Dim Sno As String
  65.     Dim h As Long
  66.     Dim intLp As Integer
  67.    
  68.     If Len(Environ("OS")) > 0 Then
  69.         h = CreateFileA("\\.\PhysicalDrive" & DrvIdx, -1073741824, 3, 0, 3, 0, 0)
  70.     Else
  71.         h = CreateFileA("\\.\Smartvsd", 0, 0, 0, 1, 0, 0)
  72.     End If

  73.     If h = 0 Then Exit Function
  74.    
  75.     RtlZeroMemory ParaIn, Len(ParaIn)
  76.     RtlZeroMemory ParaOut, Len(ParaOut)

  77.     With ParaIn
  78.         .bDriveNumber = DrvIdx
  79.         .cBufferSize = 512
  80.         With .irDriveRegs
  81.             .bDriveHeadReg = IIf(DrvIdx And 1, 176, 160)
  82.             .bCommandReg = 236
  83.             .bSectorCountReg = 1
  84.             .bSectorNumberReg = 1
  85.         End With
  86.     End With

  87.     DeviceIoControl h, 508040, ParaIn, Len(ParaIn), ParaOut, Len(ParaOut), 0, 0
  88.    
  89.     For intLp = 21 To 40 Step 2
  90.         If ParaOut.bBuffer(intLp + 1) = 0 Then Exit For
  91.         Sno = Sno & Chr(ParaOut.bBuffer(intLp + 1))
  92.         If ParaOut.bBuffer(intLp) > 0 Then Sno = Sno & Chr(ParaOut.bBuffer(intLp))
  93.     Next

  94.     CloseHandle h

  95.     Get_HD_SNo = Trim(Sno)
  96.    
  97. End Function
複製代碼



...
瀏覽完整內容,請先 註冊登入會員
分享分享0收藏收藏0支持支持0
若瀏覽伊莉的時侯發生問題或不正常情況,請使用Internet Explorer(I.E)。

使用道具檢舉

  專 家(12000/24000)

偶素程式設計下的產物「浻」

Rank: 5Rank: 5Rank: 5Rank: 5Rank: 5

帖子
1412
積分
17880 點
潛水值
38467 米
頭香
發表於 2012-6-27 08:46 PM|只看該作者
我看了一下,沒測試,我大概猜測妳問題是出在
陣列吧?

例如

Private Type SENDCMDINPARAMS
    cBufferSize As Long
    irDriveRegs As IDEREGS
    bDriveNumber As Byte
    bReserved(1 To 3) As Byte
    dwReserved(1 To 4) As Long

End Type
本人 都是寫 vb.net 如果看到本人的原創 請自備 .Net FrameWork 3.5
分享使你變得更實在,可以使其他人感到快樂,分享是我們的動力。今天就來分享你的資訊、圖片或檔案吧。

使用道具檢舉

火土水風 該用戶已被刪除
3
發表於 2012-6-27 09:43 PM|只看該作者
如果發覺自己無法使用一些功能或出現問題,請按重新整理一次,並待所有網頁內容完全載入後5秒才進行操作。
darkjack 發表於 2012-6-27 08:46 PM
下載: 訪客無法瀏覽下載點,請先 註冊登入會員

我看了一下,沒測試,我大概猜測妳問題是出在
陣列吧?

轉換後:
  1. Friend Class Form1
  2.         Inherits System.Windows.Forms.Form
  3.         '自訂型態
  4.         Private Structure IDEREGS
  5.                 Dim bFeaturesReg As Byte
  6.                 Dim bSectorCountReg As Byte
  7.                 Dim bSectorNumberReg As Byte
  8.                 Dim bCylLowReg As Byte
  9.                 Dim bCylHighReg As Byte
  10.                 Dim bDriveHeadReg As Byte
  11.                 Dim bCommandReg As Byte
  12.                 Dim bReserved As Byte
  13.         End Structure
  14.        
  15.         Private Structure DRIVERSTATUS
  16.                 Dim bDriveError As Byte
  17.                 Dim bIDEStatus As Byte
  18.                 <VBFixedArray(2)> Dim bReserved() As Byte
  19.                 <VBFixedArray(2)> Dim dwReserved() As Integer
  20.                
  21.                 'UPGRADE_TODO: 必須呼叫 "Initialize" 以初始化此結構的執行個體。 按一下以取得詳細資訊: 'ms-help://MS.VSExpressCC.v80/dv_commoner/local/redirect.htm?keyword="B4BFF9E0-8631-45CF-910E-62AB3970F27B"'
  22.                 Public Sub Initialize()
  23.                         'UPGRADE_WARNING: 陣列 bReserved 的下限已經從 1 變更成 0。 按一下以取得詳細資訊: 'ms-help://MS.VSExpressCC.v80/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
  24.                         ReDim bReserved(2)
  25.                         'UPGRADE_WARNING: 陣列 dwReserved 的下限已經從 1 變更成 0。 按一下以取得詳細資訊: 'ms-help://MS.VSExpressCC.v80/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
  26.                         ReDim dwReserved(2)
  27.                 End Sub
  28.         End Structure
  29.        
  30.         Private Structure SENDCMDOUTPARAMS
  31.                 Dim cBufferSize As Integer
  32.                 'UPGRADE_WARNING: 結構 DStatus 中的陣列在使用前需要先進行初始化。 按一下以取得詳細資訊: 'ms-help://MS.VSExpressCC.v80/dv_commoner/local/redirect.htm?keyword="814DF224-76BD-4BB4-BFFB-EA359CB9FC48"'
  33.                 Dim DStatus As DRIVERSTATUS
  34.                 <VBFixedArray(512)> Dim bBuffer() As Byte
  35.                
  36.                 'UPGRADE_TODO: 必須呼叫 "Initialize" 以初始化此結構的執行個體。 按一下以取得詳細資訊: 'ms-help://MS.VSExpressCC.v80/dv_commoner/local/redirect.htm?keyword="B4BFF9E0-8631-45CF-910E-62AB3970F27B"'
  37.                 Public Sub Initialize()
  38.                         DStatus.Initialize()
  39.                         'UPGRADE_WARNING: 陣列 bBuffer 的下限已經從 1 變更成 0。 按一下以取得詳細資訊: 'ms-help://MS.VSExpressCC.v80/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
  40.                         ReDim bBuffer(512)
  41.                 End Sub
  42.         End Structure
  43.        
  44.         Private Structure SENDCMDINPARAMS
  45.                 Dim cBufferSize As Integer
  46.                 Dim irDriveRegs As IDEREGS
  47.                 Dim bDriveNumber As Byte
  48.                 <VBFixedArray(3)> Dim bReserved() As Byte
  49.                 <VBFixedArray(4)> Dim dwReserved() As Integer
  50.                
  51.                 'UPGRADE_TODO: 必須呼叫 "Initialize" 以初始化此結構的執行個體。 按一下以取得詳細資訊: 'ms-help://MS.VSExpressCC.v80/dv_commoner/local/redirect.htm?keyword="B4BFF9E0-8631-45CF-910E-62AB3970F27B"'
  52.                 Public Sub Initialize()
  53.                         'UPGRADE_WARNING: 陣列 bReserved 的下限已經從 1 變更成 0。 按一下以取得詳細資訊: 'ms-help://MS.VSExpressCC.v80/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
  54.                         ReDim bReserved(3)
  55.                         'UPGRADE_WARNING: 陣列 dwReserved 的下限已經從 1 變更成 0。 按一下以取得詳細資訊: 'ms-help://MS.VSExpressCC.v80/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
  56.                         ReDim dwReserved(4)
  57.                 End Sub
  58.         End Structure
  59.        
  60.         'API宣告
  61.         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
  62.        
  63.         'UPGRADE_ISSUE: 不支援宣告參數 'As Any'。 按一下以取得詳細資訊: 'ms-help://MS.VSExpressCC.v80/dv_commoner/local/redirect.htm?keyword="FAE78A8D-8978-4FD4-8208-5B7324A8F795"'
  64.     Private Declare Sub RtlZeroMemory Lib "Kernel32" (ByRef dest As Object, ByVal numBytes As Integer)
  65.        
  66.         'UPGRADE_ISSUE: 不支援宣告參數 'As Any'。 按一下以取得詳細資訊: 'ms-help://MS.VSExpressCC.v80/dv_commoner/local/redirect.htm?keyword="FAE78A8D-8978-4FD4-8208-5B7324A8F795"'
  67.         'UPGRADE_ISSUE: 不支援宣告參數 'As Any'。 按一下以取得詳細資訊: 'ms-help://MS.VSExpressCC.v80/dv_commoner/local/redirect.htm?keyword="FAE78A8D-8978-4FD4-8208-5B7324A8F795"'
  68.     Private Declare Function DeviceIoControl Lib "Kernel32" (ByVal hDevice As Integer, ByVal dwIoControlCode As Integer, ByRef lpInBuffer As Object, ByVal nInBufferSize As Integer, ByRef lpOutBuffer As Object, ByVal nOutBufferSize As Integer, ByRef lpBytesReturned As Integer, ByVal lpOverlapped As Integer) As Integer
  69.        
  70.         Private Declare Function CloseHandle Lib "Kernel32" (ByVal hObject As Integer) As Integer
  71.        
  72.        
  73.         'UPGRADE_ISSUE: 不支援宣告參數 'As Any'。 按一下以取得詳細資訊: 'ms-help://MS.VSExpressCC.v80/dv_commoner/local/redirect.htm?keyword="FAE78A8D-8978-4FD4-8208-5B7324A8F795"'
  74.         'UPGRADE_ISSUE: 不支援宣告參數 'As Any'。 按一下以取得詳細資訊: 'ms-help://MS.VSExpressCC.v80/dv_commoner/local/redirect.htm?keyword="FAE78A8D-8978-4FD4-8208-5B7324A8F795"'
  75.     Private Declare Sub RtlMoveMemory Lib "Kernel32" (ByRef Destination As Object, ByRef Source As Object, ByVal Length As Integer)
  76.        
  77.         Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click
  78.                 MsgBox("硬碟序號 : " & Get_HD_SNo(0)) ' 第一顆硬碟.
  79.         End Sub
  80.        
  81.         ' 取得硬碟序號
  82.         Private Function Get_HD_SNo(ByRef DrvIdx As Byte) As String
  83.                
  84.                 'UPGRADE_WARNING: 結構 ParaIn 中的陣列在使用前需要先進行初始化。 按一下以取得詳細資訊: 'ms-help://MS.VSExpressCC.v80/dv_commoner/local/redirect.htm?keyword="814DF224-76BD-4BB4-BFFB-EA359CB9FC48"'
  85.                 Dim ParaIn As SENDCMDINPARAMS
  86.                 'UPGRADE_WARNING: 結構 ParaOut 中的陣列在使用前需要先進行初始化。 按一下以取得詳細資訊: 'ms-help://MS.VSExpressCC.v80/dv_commoner/local/redirect.htm?keyword="814DF224-76BD-4BB4-BFFB-EA359CB9FC48"'
  87.                 Dim ParaOut As SENDCMDOUTPARAMS
  88.                 Dim Sno As String
  89.                 Dim h As Integer
  90.                 Dim intLp As Short
  91.                
  92.                 If Len(Environ("OS")) > 0 Then
  93.                         h = CreateFileA("\\.\PhysicalDrive" & DrvIdx, -1073741824, 3, 0, 3, 0, 0)
  94.                 Else
  95.                         h = CreateFileA("\\.\Smartvsd", 0, 0, 0, 1, 0, 0)
  96.                 End If
  97.                
  98.                 If h = 0 Then Exit Function
  99.                
  100.                 'UPGRADE_WARNING: 無法解析物件 ParaIn 的預設屬性。 按一下以取得詳細資訊: 'ms-help://MS.VSExpressCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
  101.                 RtlZeroMemory(ParaIn, Len(ParaIn))
  102.                 'UPGRADE_WARNING: 無法解析物件 ParaOut 的預設屬性。 按一下以取得詳細資訊: 'ms-help://MS.VSExpressCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
  103.                 RtlZeroMemory(ParaOut, Len(ParaOut))
  104.                
  105.                 With ParaIn
  106.                         .bDriveNumber = DrvIdx
  107.                         .cBufferSize = 512
  108.                         With .irDriveRegs
  109.                                 .bDriveHeadReg = IIf(DrvIdx And 1, 176, 160)
  110.                                 .bCommandReg = 236
  111.                                 .bSectorCountReg = 1
  112.                                 .bSectorNumberReg = 1
  113.                         End With
  114.                 End With
  115.                
  116.                 'UPGRADE_WARNING: 無法解析物件 ParaOut 的預設屬性。 按一下以取得詳細資訊: 'ms-help://MS.VSExpressCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
  117.                 'UPGRADE_WARNING: 無法解析物件 ParaIn 的預設屬性。 按一下以取得詳細資訊: 'ms-help://MS.VSExpressCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
  118.                 DeviceIoControl(h, 508040, ParaIn, Len(ParaIn), ParaOut, Len(ParaOut), 0, 0)
  119.                
  120.                 For intLp = 21 To 40 Step 2
  121.                         If ParaOut.bBuffer(intLp + 1) = 0 Then Exit For
  122.                         Sno = Sno & Chr(ParaOut.bBuffer(intLp + 1))
  123.                         If ParaOut.bBuffer(intLp) > 0 Then Sno = Sno & Chr(ParaOut.bBuffer(intLp))
  124.                 Next
  125.                
  126.                 CloseHandle(h)
  127.                
  128.                 Get_HD_SNo = Trim(Sno)
  129.                
  130.         End Function
  131. End Class
複製代碼
...
瀏覽完整內容,請先 註冊登入會員

使用道具檢舉

  專 家(12000/24000)

偶素程式設計下的產物「浻」

Rank: 5Rank: 5Rank: 5Rank: 5Rank: 5

帖子
1412
積分
17880 點
潛水值
38467 米
4
發表於 2012-6-27 11:32 PM|只看該作者
分享使你變得更實在,可以使其他人感到快樂,分享是我們的動力。今天就來分享你的資訊、圖片或檔案吧。
我的技術(到處查)只能到這邊
是沒有出錯,但是 值 就是沒法 跟 vb6 一樣出的來

有些有多餘的程式碼 妳可以斟酌刪除
  1. Public Class Form1
  2.   Public Structure IDEREGS
  3.     Dim bFeaturesReg As Byte
  4.     Dim bSectorCountReg As Byte
  5.     Dim bSectorNumberReg As Byte
  6.     Dim bCylLowReg As Byte
  7.     Dim bCylHighReg As Byte
  8.     Dim bDriveHeadReg As Byte
  9.     Dim bCommandReg As Byte
  10.     Dim bReserved As Byte
  11.   End Structure

  12.   Public Structure DRIVERSTATUS
  13.     Dim bDriveError As Byte
  14.     Dim bIDEStatus As Byte
  15.     <VBFixedArray(2)> Public bReserved As Byte
  16.     <VBFixedArray(2)> Public dwReserved As Integer
  17.   End Structure

  18.   Public Structure SENDCMDOUTPARAMS
  19.     Dim cBufferSize As Integer
  20.     Dim DStatus As DRIVERSTATUS
  21.     <VBFixedArray(512)> Public bBuffer As Byte
  22.   End Structure

  23.   Public Structure SENDCMDINPARAMS
  24.     Dim cBufferSize As Integer
  25.     Dim irDriveRegs As IDEREGS
  26.     Dim bDriveNumber As Byte
  27.     <VBFixedArray(3)> Public bReserved As Byte
  28.     <VBFixedArray(4)> Public dwReserved As Integer
  29.   End Structure

  30.   'API宣告
  31.   Private Declare Function CreateFileA Lib "Kernel32" (ByVal lpFileName As String, ByVal dwDesiredAccess As Integer, _
  32.       ByVal dwShareMode As Integer, ByVal lpSecurityAttributes As Integer, ByVal dwCreationDisposition As Integer, _
  33.       ByVal dwFlagsAndAttributes As Integer, ByVal hTemplateFile As Integer) As Integer

  34.   Private Declare Sub RtlZeroMemory Lib "Kernel32" Alias "RtlZeroMemory" (ByVal dest As SENDCMDINPARAMS, ByVal numBytes As Integer)
  35.   Private Declare Sub RtlZeroMemory Lib "Kernel32" Alias "RtlZeroMemory" (ByVal dest As SENDCMDOUTPARAMS, ByVal numBytes As Integer)

  36.   Private Declare Function DeviceIoControl Lib "Kernel32" _
  37.     (ByVal hDevice As Integer, _
  38.     ByVal dwIoControlCode As Integer, _
  39.     ByVal lpInBuffer As SENDCMDINPARAMS, _
  40.     ByVal nInBufferSize As SENDCMDINPARAMS, _
  41.     ByVal lpOutBuffer As SENDCMDOUTPARAMS, _
  42.     ByVal nOutBufferSize As SENDCMDOUTPARAMS, _
  43.     ByVal lpBytesReturned As Integer, _
  44.     ByVal lpOverlapped As Integer) As Integer

  45.   Private Declare Function DeviceIoControl Lib "Kernel32" _
  46.     (ByVal hDevice As Integer, _
  47.     ByVal dwIoControlCode As Integer, _
  48.     ByRef lpInBuffer As SENDCMDINPARAMS, _
  49.     ByVal nInBufferSize As Integer, _
  50.     ByRef lpOutBuffer As SENDCMDOUTPARAMS, _
  51.     ByVal nOutBufferSize As Integer, _
  52.     ByVal lpBytesReturned As Integer, _
  53.     ByVal lpOverlapped As Integer) As Integer





  54.   Private Declare Function CloseHandle Lib "Kernel32" _
  55.       (ByVal hObject As Integer) As Integer


  56.   Private Declare Sub RtlMoveMemory Lib "Kernel32" _
  57.       (ByVal Destination As IntPtr, ByVal Source As IntPtr, ByVal Length As Integer)



  58.   ' 取得硬碟序號
  59.   Private Function Get_HD_SNo(ByVal DrvIdx As Byte) As String

  60.     Dim ParaIn As SENDCMDINPARAMS
  61.     Dim ParaOut As SENDCMDOUTPARAMS

  62.     Dim ParaIn1() As SENDCMDINPARAMS
  63.     Dim ParaOut1() As SENDCMDOUTPARAMS
  64.     'Dim ParaIn As New SENDCMDINPARAMS
  65.     'Dim ParaOut As New SENDCMDOUTPARAMS

  66.     Dim Sno As String
  67.     Dim h As Integer
  68.     Dim intLp As Integer

  69.     If Len(Environ("OS")) > 0 Then
  70.       h = CreateFileA("\\.\PhysicalDrive" & DrvIdx, -1073741824, 3, 0, 3, 0, 0)
  71.     Else
  72.       h = CreateFileA("\\.\Smartvsd", 0, 0, 0, 1, 0, 0)
  73.     End If

  74.     If h = 0 Then
  75.       Exit Function
  76.     End If


  77.     RtlZeroMemory(ParaIn, Len(ParaIn))
  78.     RtlZeroMemory(ParaOut, Len(ParaOut))

  79.     With ParaIn
  80.       .bDriveNumber = DrvIdx
  81.       .cBufferSize = 512
  82.       With .irDriveRegs
  83.         .bDriveHeadReg = IIf(DrvIdx And 1, 176, 160)
  84.         .bCommandReg = 236
  85.         .bSectorCountReg = 1
  86.         .bSectorNumberReg = 1
  87.       End With
  88.     End With

  89.     DeviceIoControl(h, 508040, ParaIn, Len(ParaIn), ParaOut, Len(ParaOut), 0, 0)

  90.     'For intLp = 21 To 40 Step 2
  91.     'If ParaOut.bBuffer(intLp + 1) = 0 Then Exit For
  92.     'Sno = Sno & Chr(ParaOut.bBuffer(intLp + 1))
  93.     'If ParaOut.bBuffer(intLp) > 0 Then Sno = Sno & Chr(ParaOut.bBuffer(intLp))
  94.     'Next

  95.     Dim tmp As Integer


  96.     For intLp = 21 To 40 Step 2
  97.       tmp = intLp + 1
  98.       ReDim Preserve ParaOut1(0 To 511)
  99.       ParaOut.bBuffer = tmp

  100.       Sno &= Chr(ParaOut.bBuffer)

  101.     Next
  102.     tmp = Byte.Parse(21)
  103.     'ParaOut.bBuffer = 1
  104.     CloseHandle(h)

  105.     Get_HD_SNo = Trim(Sno)

  106.   End Function


  107.   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

  108.     MsgBox("硬碟序號 : " & Get_HD_SNo(0)) ' 第一顆硬碟.
  109.   End Sub

  110.   Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  111.     Dim xxxxx
  112.     For intLp = 21 To 40 Step 2

  113.       xxxxx &= Chr(intLp)

  114.     Next
  115.     MsgBox(xxxxx)
  116.   End Sub
  117. End Class
複製代碼
...
瀏覽完整內容,請先 註冊登入會員
本人 都是寫 vb.net 如果看到本人的原創 請自備 .Net FrameWork 3.5

使用道具檢舉

火土水風 該用戶已被刪除
5
發表於 2012-6-28 12:39 AM|只看該作者
分享使你變得更實在,可以使其他人感到快樂,分享是我們的動力。今天就來分享你的資訊、圖片或檔案吧。
darkjack 發表於 2012-6-27 11:32 PM
下載: 訪客無法瀏覽下載點,請先 註冊登入會員

我的技術(到處查)只能到這邊
是沒有出錯,但是 值 就是沒法 跟 vb6 一樣出的來

值差的好多0.0
問一下...同樣都是查硬碟機器碼..怎會有差@@?...
瀏覽完整內容,請先 註冊登入會員





使用道具檢舉

  專 家(12000/24000)

偶素程式設計下的產物「浻」

Rank: 5Rank: 5Rank: 5Rank: 5Rank: 5

帖子
1412
積分
17880 點
潛水值
38467 米
6
發表於 2012-6-28 06:35 AM|只看該作者
若新密碼無法使用,可能是數據未更新。請使用舊密碼看看。
本帖最後由 darkjack 於 2012-6-28 06:39 AM 編輯

因為 問題就是出在
vb6
  1. For intLp = 21 To 40 Step 2
  2.                         If ParaOut.bBuffer(intLp + 1) = 0 Then Exit For
  3.                         Sno = Sno & Chr(ParaOut.bBuffer(intLp + 1))
  4.                         If ParaOut.bBuffer(intLp) > 0 Then Sno = Sno & Chr(ParaOut.bBuffer(intLp))
  5.                 Next
複製代碼
我 vb.net 根本就沒法像 vb6 那樣的設定 (妳自己知道會出現啥錯誤)
所以 vb.net 才會改用 WMI 方式去取硬碟序號
只是 WMI 硬碟序號我之前有玩過,且硬碟序號可以改,用這個並沒有很大意義(保護)


vb6 內 ParaOut.bBuffer(intLp + 1)
這裡面就已經包含了 512 byte 的字元 , for 只是 去取陣列的位置而已
...
瀏覽完整內容,請先 註冊登入會員
本人 都是寫 vb.net 如果看到本人的原創 請自備 .Net FrameWork 3.5

使用道具檢舉

  專 家(12000/24000)

落葉知秋

Rank: 5Rank: 5Rank: 5Rank: 5Rank: 5

帖子
1600
積分
23884 點
潛水值
54991 米
7
發表於 2012-6-28 08:38 AM|只看該作者
如果發覺自己無法使用一些功能或出現問題,請按重新整理一次,並待所有網頁內容完全載入後5秒才進行操作。
我是覺得...如果用 vb.net 的話,
直接用 WMI 的方式,簡單寫幾行程式碼去抓比較快,
這就是 .net 的好處阿!
新手就更該多用「心」動「手」找答案;
經驗是累積來的,答案則是 Google 來的。
若瀏覽伊莉的時侯發生問題或不正常情況,請使用Internet Explorer(I.E)。

使用道具檢舉

您需要登錄後才可以回帖 登錄 | 註冊

Powered by Discuz!

© Comsenz Inc.

重要聲明:本討論區是以即時上載留言的方式運作,對所有留言的真實性、完整性及立場等,不負任何法律責任。而一切留言之言論只代表留言者個人意見,並非本網站之立場,用戶不應信賴內容,並應自行判斷內容之真實性。於有關情形下,用戶應尋求專業意見(如涉及醫療、法律或投資等問題)。 由於本討論區受到「即時上載留言」運作方式所規限,故不能完全監察所有留言,若讀者發現有留言出現問題,請聯絡我們。有權刪除任何留言及拒絕任何人士上載留言,同時亦有不刪除留言的權利。切勿上傳和撰寫 侵犯版權(未經授權)、粗言穢語、誹謗、渲染色情暴力或人身攻擊的言論,敬請自律。本網站保留一切法律權利。
回頂部