Get Windows 8 product key through VB script

I (am) was very very very good in Visual Basic 6.0 and a long time programmer on it. For quick and basic UI generation I still use it, its easier much easier for me. From Windows 8, Microsoft hides the Windows product key in Window OEM laptops’s BIOS and its safer and easier then the traditional sticker way. Few months back my cousin called me and asked me can we get get the product key of Windows 8 and we together did some researches (you might call them as hacks) and found something called “DigitalProductId” is stored in registry in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion


And we found, it stores the Windows product key there as a REG_BINARY type value. Then we make the older reghack algo to use here and found the key 🙂 One day while I was in campus, my cousin called me and said, he need to find a key for an urgent, and sent me the value of “DigitalProductId” and I went through the same process and sent him the key back. Finally I thought to give a small program to him so, he can get the key of a system if he just the program, I was thinking of C#, but it will not work as we have to install dotNet 3.5 in all Windows 8 PCs, so I made a VB script file and gave it to him. Just double clicking the file gives the key via a Message box.. its cool isn’t it. Yes, here is the script, download it and use it if you like 😉

'Constants for our registry query
const HKEY_LOCAL_MACHINE = &H80000002 
sRegistryKeyName = "SOFTWARE\Microsoft\Windows NT\CurrentVersion"
sRegistryValueName = "DigitalProductId"

function GetProductKey
	dim pValues()
	Set poRegistry=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
	poRegistry.GetBinaryValue HKEY_LOCAL_MACHINE,sRegistryKeyName,sRegistryValueName,pValues

	Dim sArrayPID
	sArrayPID = Array()

	For i = 52 to 66
		ReDim Preserve sArrayPID( UBound(sArrayPID) + 1 )
		sArrayPID(UBound(sArrayPID)) = pValues(i)

	Dim sProductKeyChars
	sProductKeyChars = 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 sArrayPID(j)
			sArrayPID(j) = Int(k / 24)
			k = k Mod 24
		sProductKey = sProductKeyChars(k) & sProductKey
		if i Mod 5 = 0 And i <> 0 Then sProductKey = "-" & sProductKey
	GetProductKey = sProductKey
end function

function GetOSVersion
	Set SystemSet = GetObject("winmgmts:").InstancesOf ("Win32_OperatingSystem") 
	for each System in SystemSet 
		GetOSVersion = Trim(System.Caption) & " (" & System.Version & ")"
end function 

wscript.echo GetOSVersion & ", " & GetProductKey

Note : The same way works for Windows 8.1 also.

One thought on “Get Windows 8 product key through VB script

  1. Hey Isham, this script works well for Windows 7 and below but it is not giving correct cd keys for windows 8/8.1. As microsoft has changed its encryption method for windows 8.Let me know if you find the updated decoding method.
    Thank You

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s