V
Victor Torres
Hi to all, I create a small program that I can use to registry my database
apps. It use the Windows CD Key in order to registry the software. Right
now I can do it in windows XP. But I try it in Windows Vista and it doesn't
do it. I don't know why. I'm not an expert. I just use logic to manage to
change and convert some code so I don't know what the code is doing. If
someone know how codes works and have a windows vista that can verify the
code to see what is wrong and why is not working I will be glad. Here is
the code that I use to retrieve windows Key. I found this code in the
internet and I just put it to work with windows. If anyone know also how to
shrink it so it doesn't use the array well I will be glad to:
Private Sub ButtonKey_Click()
' ##############################################################
' # #
' # VBScript to retrieve Microsoft Product Keys #
' # from the registry by decoding DigitalProductID's #
' # #
' # -------------------------------------------------- #
' # Created by: Parabellum #
' # #
' ##############################################################
'
Const HKEY_LOCAL_MACHINE = &H80000002
Const SEARCH_KEY = "DigitalProductID"
Dim arrSubKeys(0, 1)
Dim foundKeys
Dim iValues, arrDPID
foundKeys = Array()
iValues = Array()
arrSubKeys(0, 0) = "Microsoft Windows Product Key"
arrSubKeys(0, 1) = "SOFTWARE\Microsoft\Windows NT\CurrentVersion"
'arrSubKeys(2, 0) = "Microsoft Office XP"
'arrSubKeys(2, 1) = "SOFTWARE\Microsoft\Office\10.0\Registration"
'arrSubKeys(1, 0) = "Microsoft Office 2003"
'arrSubKeys(1, 1) = "SOFTWARE\Microsoft\Office\11.0\Registration"
'arrSubKeys(3, 0) = "Microsoft Office 2007"
'arrSubKeys(3, 1) = "SOFTWARE\Microsoft\Office\12.0\Registration"
'arrSubKeys(1, 0) = "Microsoft Exchange Product Key"
'arrSubKeys(1, 1) = "SOFTWARE\Microsoft\Exchange\Setup"
' <--------------- Open Registry Key and populate binary data into an array
-------------------------->
strComputer = "."
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &
strComputer & "\root\default:StdRegProv")
For x = LBound(arrSubKeys, 1) To UBound(arrSubKeys, 1)
oReg.GetBinaryValue HKEY_LOCAL_MACHINE, arrSubKeys(x, 1), SEARCH_KEY,
arrDPIDBytes
If Not IsNull(arrDPIDBytes) Then
Call decodeKey(arrDPIDBytes, arrSubKeys(x, 0))
Else
oReg.EnumKey HKEY_LOCAL_MACHINE, arrSubKeys(x, 1), arrGUIDKeys
If Not IsNull(arrGUIDKeys) Then
For Each GUIDKey In arrGUIDKeys
oReg.GetBinaryValue HKEY_LOCAL_MACHINE, arrSubKeys(x, 1) & "\" & GUIDKey,
SEARCH_KEY, arrDPIDBytes
If Not IsNull(arrDPIDBytes) Then
Call decodeKey(arrDPIDBytes, arrSubKeys(x, 0))
End If
Next
End If
End If
Next
End Sub
' <----------------------------------------- Return the Product Key
--------------------------------------------------->
Function decodeKey(iValues, strProduct)
Dim arrDPID
arrDPID = Array()
' <--------------- extract bytes 52-66 of the DPID -------------------------->
For i = 52 To 66
ReDim Preserve arrDPID(UBound(arrDPID) + 1)
arrDPID(UBound(arrDPID)) = iValues(i)
Next
' <--------------- Create an array to hold the valid characters for a
microsoft Product Key -------------------------->
Dim arrChars
arrChars = Array("B", "C", "D", "F", "G", "H", "J", "K", "M", "P", "Q", "R",
"T", "V", "W", "X", "Y", "2", "3", "4", "6", "7", "8", "9")
' <--------------- The clever bit !!! (decode the base24 encoded binary
data)-------------------------->
For i = 24 To 0 Step -1
K = 0
For J = 14 To 0 Step -1
K = K * 256 Xor arrDPID(J)
arrDPID(J) = Int(K / 24)
K = K Mod 24
Next
strProductKey = arrChars(K) & strProductKey
' If i Mod 5 = 0 And i <> 0 Then strProductKey = "-" & strProductKey
Next
msgbox strProductKey
End Function
apps. It use the Windows CD Key in order to registry the software. Right
now I can do it in windows XP. But I try it in Windows Vista and it doesn't
do it. I don't know why. I'm not an expert. I just use logic to manage to
change and convert some code so I don't know what the code is doing. If
someone know how codes works and have a windows vista that can verify the
code to see what is wrong and why is not working I will be glad. Here is
the code that I use to retrieve windows Key. I found this code in the
internet and I just put it to work with windows. If anyone know also how to
shrink it so it doesn't use the array well I will be glad to:
Private Sub ButtonKey_Click()
' ##############################################################
' # #
' # VBScript to retrieve Microsoft Product Keys #
' # from the registry by decoding DigitalProductID's #
' # #
' # -------------------------------------------------- #
' # Created by: Parabellum #
' # #
' ##############################################################
'
Const HKEY_LOCAL_MACHINE = &H80000002
Const SEARCH_KEY = "DigitalProductID"
Dim arrSubKeys(0, 1)
Dim foundKeys
Dim iValues, arrDPID
foundKeys = Array()
iValues = Array()
arrSubKeys(0, 0) = "Microsoft Windows Product Key"
arrSubKeys(0, 1) = "SOFTWARE\Microsoft\Windows NT\CurrentVersion"
'arrSubKeys(2, 0) = "Microsoft Office XP"
'arrSubKeys(2, 1) = "SOFTWARE\Microsoft\Office\10.0\Registration"
'arrSubKeys(1, 0) = "Microsoft Office 2003"
'arrSubKeys(1, 1) = "SOFTWARE\Microsoft\Office\11.0\Registration"
'arrSubKeys(3, 0) = "Microsoft Office 2007"
'arrSubKeys(3, 1) = "SOFTWARE\Microsoft\Office\12.0\Registration"
'arrSubKeys(1, 0) = "Microsoft Exchange Product Key"
'arrSubKeys(1, 1) = "SOFTWARE\Microsoft\Exchange\Setup"
' <--------------- Open Registry Key and populate binary data into an array
-------------------------->
strComputer = "."
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &
strComputer & "\root\default:StdRegProv")
For x = LBound(arrSubKeys, 1) To UBound(arrSubKeys, 1)
oReg.GetBinaryValue HKEY_LOCAL_MACHINE, arrSubKeys(x, 1), SEARCH_KEY,
arrDPIDBytes
If Not IsNull(arrDPIDBytes) Then
Call decodeKey(arrDPIDBytes, arrSubKeys(x, 0))
Else
oReg.EnumKey HKEY_LOCAL_MACHINE, arrSubKeys(x, 1), arrGUIDKeys
If Not IsNull(arrGUIDKeys) Then
For Each GUIDKey In arrGUIDKeys
oReg.GetBinaryValue HKEY_LOCAL_MACHINE, arrSubKeys(x, 1) & "\" & GUIDKey,
SEARCH_KEY, arrDPIDBytes
If Not IsNull(arrDPIDBytes) Then
Call decodeKey(arrDPIDBytes, arrSubKeys(x, 0))
End If
Next
End If
End If
Next
End Sub
' <----------------------------------------- Return the Product Key
--------------------------------------------------->
Function decodeKey(iValues, strProduct)
Dim arrDPID
arrDPID = Array()
' <--------------- extract bytes 52-66 of the DPID -------------------------->
For i = 52 To 66
ReDim Preserve arrDPID(UBound(arrDPID) + 1)
arrDPID(UBound(arrDPID)) = iValues(i)
Next
' <--------------- Create an array to hold the valid characters for a
microsoft Product Key -------------------------->
Dim arrChars
arrChars = Array("B", "C", "D", "F", "G", "H", "J", "K", "M", "P", "Q", "R",
"T", "V", "W", "X", "Y", "2", "3", "4", "6", "7", "8", "9")
' <--------------- The clever bit !!! (decode the base24 encoded binary
data)-------------------------->
For i = 24 To 0 Step -1
K = 0
For J = 14 To 0 Step -1
K = K * 256 Xor arrDPID(J)
arrDPID(J) = Int(K / 24)
K = K Mod 24
Next
strProductKey = arrChars(K) & strProductKey
' If i Mod 5 = 0 And i <> 0 Then strProductKey = "-" & strProductKey
Next
msgbox strProductKey
End Function