我正在尝试使用我的VB6应用程序获取Windows 7中的Windows序列号。但是,它始终无法检索它。
SScript.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductId")
它返回以下错误:
Unable to open registry key "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductId" for reading.
在Win XP中,将成功检索序列号。我不知道Windows 7是否禁止VB6应用程序获取Windows序列号。
请帮忙。谢谢!
答案 0 :(得分:2)
这是奇特的不是吗?尝试将此const添加到您的delcarations中,并将 OR 添加到打开的注册表调用中。在KEY_WOW64_32KEY and 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