'Retrieve your windows Product Key

Dim Objshell, sInput, sMsg

Set wshShell=CreateObject("wscript.shell")

If WScript.Arguments.Count = 0 Then
Set Objshell = CreateObject("Shell.Application") 
Objshell.ShellExecute "wscript.exe",  """" & _
WScript.ScriptFullName &  """" &_
 " RunAsAdministrator", , "runas", 1 
Else

sMsg = "This script will retrieve your Windows Product Key." & vbCr & vbCr  _
& "If you do not trust the source of this information, do not add it to the registry."  & vbCr  & vbCr _  
& "Would you like to continue?"

sInput = MsgBox(sMsg, vbYesNo + vbInformation, "Paul's XP, Vista and Windows 7 Tweaks")
If sInput = vbYes Then 
const HKEY_LOCAL_MACHINE = &H80000002
strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion"
strValueName = "DigitalProductId"
strComputer = "." 

dim iValues()

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
        strComputer & "\root\default:StdRegProv")
oReg.GetBinaryValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,iValues
Dim arrDPID
arrDPID = Array()
For i = 52 to 66
ReDim Preserve arrDPID( UBound(arrDPID) + 1 )
arrDPID( UBound(arrDPID) ) = iValues(i)

Next

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")
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

strFinalKey = strProductKey
strComputer = "." 
Set objWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")

For Each objOperatingSystem in colOperatingSystems
    strOS   = objOperatingSystem.Caption
    strBuild   = objOperatingSystem.BuildNumber
    strSerial   = objOperatingSystem.SerialNumber
    strRegistered  = objOperatingSystem.RegisteredUser

 Next

MsgBox "" & strOS & vbCr & vbcr & _ 
    "Build Number:  " & strBuild & vbCr & _ 
    "Registered to:  " & strRegistered & vbCr & vbCr & _
    "PID:  " & strSerial & vbCr & vbCr & _
    "Your Windows Product Key is:" & vbCr & strFinalKey  & vbCr & vbCr & _
    "This script was downloaded from www.paulsxp.com" ,64,"Microsoft Windows License Information"
End If
End If
 
