'==========================================================================
' NAME: GetCDKeyandSerialNumber.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: [URL unfurl="true"]http://www.thespidersparlor.com[/URL]
' DATE : 3/16/2006
' (C) 2006, All Rights Reserved
'
' COMMENT:
'
'==========================================================================
Set WshShell = CreateObject("wscript.Shell")
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set env = WshShell.environment("Process")
strComputer = env.Item("Computername")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Const HKEY_LOCAL_MACHINE = &H80000002
Const UnInstPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
".\root\default:StdRegProv")
strDigitalProductId="HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DigitalProductId"
strXPKey=GetKey(WshShell.RegRead(strDigitalProductId))
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
For Each objItem in colItems
report = report & "Original CD Key:"& strXPKey & vbCrLf
report = report & "SerialNumber: " & objItem.SerialNumber & vbCrLf
Next
MsgBox report
Function GetKey(rpk)
Const rpkOffset=52:i=28
szPossibleChars="BCDFGHJKMPQRTVWXY2346789"
Do 'Rep1
dwAccumulator=0 : j=14
Do
dwAccumulator=dwAccumulator*256
dwAccumulator=rpk(j+rpkOffset)+dwAccumulator
rpk(j+rpkOffset)=(dwAccumulator\24) and 255
dwAccumulator=dwAccumulator Mod 24
j=j-1
Loop While j>=0
i=i-1 : szProductKey=mid(szPossibleChars,dwAccumulator+1,1)&szProductKey
if (((29-i) Mod 6)=0) and (i<>-1) then
i=i-1 : szProductKey="-"&szProductKey
End If
Loop While i>=0 'Goto Rep1
GetKey=szProductKey
End Function