是不是很奇特?尝试将此 const 添加到您的声明中,或者将值添加到您的开放注册表调用中。KEY_WOW64_32KEY 和 KEY_WOW64_64KEY的答案中有一个很好的解释。
Private Const KEY_WOW64_64KEY As Long = &H100& '32 bit app to access 64 bit hive
Private Function GetWindowsProductId() As String
Dim strReturn As String
Dim strBuffer As String
Dim lngType As Long
Dim lngBufLen As Long
Dim lngRst As Long
Dim hKeyHandle As Long
lngRst = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows NT\CurrentVersion", 0, KEY_READ Or KEY_WOW64_64KEY, hKeyHandle)
If hKeyHandle <> 0 Then
strBuffer = String(255, vbNullChar)
lngBufLen = Len(strBuffer)
lngRst = RegQueryValueEx(hKeyHandle, "ProductId", ByVal 0&, lngType, ByVal strBuffer, lngBufLen)
If lngRst = 0 Then
If lngType = REG_SZ Then
If lngBufLen > 0 Then
strReturn = Left$(strBuffer, lngBufLen - 1)
Else
strReturn = "nothing was returned"
End If
Else
strReturn = "there was an error"
End If
ElseIf lngRst = 2 Then 'the key does not exist
strReturn = "the key was not found"
Else 'if the return is non-zero there was an error
strReturn = "There was an error " & CStr(lngRst) & " reading the key"
End If
End If
GetWindowsProductId = strReturn
End Function