我遇到了这个用来从我的电脑中检索产品密钥的功能的问题。
Public Function GetProductKey(ByVal KeyPath As String, ByVal ValueName As String) As String
Dim HexBuf As Object = My.Computer.Registry.GetValue(KeyPath, ValueName, 0)
If HexBuf Is Nothing Then Return "N/A"
Dim tmp As String = String.Empty
For l As Integer = LBound(CType(HexBuf, Array)) To UBound(CType(HexBuf, Array))
tmp = tmp & " " & Hex(CByte(AscW(HexBuf.ToString(1))))
Next
Dim StartOffset As Integer = 52
Dim EndOffset As Integer = 67
Dim Digits(24) As String
Digits(0) = "B" : Digits(1) = "C" : Digits(2) = "D" : Digits(3) = "F"
Digits(4) = "G" : Digits(5) = "H" : Digits(6) = "J" : Digits(7) = "K"
Digits(8) = "M" : Digits(9) = "P" : Digits(10) = "Q" : Digits(11) = "R"
Digits(12) = "T" : Digits(13) = "V" : Digits(14) = "W" : Digits(15) = "X"
Digits(16) = "Y" : Digits(17) = "2" : Digits(18) = "3" : Digits(19) = "4"
Digits(20) = "6" : Digits(21) = "7" : Digits(22) = "8" : Digits(23) = "9"
Dim dLen As Integer = 29
Dim sLen As Integer = 15
Dim HexDigitalPID(15) As String
Dim Des(30) As String
Dim tmp2 As String = String.Empty
Dim notbuffer As Array = CType(HexBuf, Array)
For i = StartOffset To EndOffset
HexDigitalPID(i - StartOffset) = notbuffer.GetValue(i).ToString
tmp2 = tmp2 & " " & Hex(HexDigitalPID(i - StartOffset))
Next
Dim KEYSTRING As String = String.Empty
For i As Integer = dLen - 1 To 0 Step -1
If ((i + 1) Mod 6) = 0 Then
Des(i) = "-"
KEYSTRING = KEYSTRING & "-"
Else
Dim HN As Integer = 0
For N As Integer = (sLen - 1) To 0 Step -1
Dim Value As Integer = CInt(CLng((HN * 2 ^ 8)) Or CLng(HexDigitalPID(N)))
HexDigitalPID(N) = (Value \ 24).ToString
HN = (Value Mod 24)
Next
Des(i) = Digits(HN)
KEYSTRING = KEYSTRING & Digits(HN)
End If
Next
Return StrReverse(KEYSTRING)
End Function
如果我使用x64或AnyCPU架构编译,这很有效,但如果我把x86(这是我想要的)它会抛出这个错误: http://i.imgur.com/Kfpa7mh.png
它说:“无法将对象类型System.Int32与System.Array相关联” 我无法弄清楚问题,我不能为那个论点做一个Next? 为什么这适用于x64和AnyCPU(因为我有64位操作系统,仍然是x64)而不是x86?
感谢。