Emnico in Swindon and its partners
in the UK and Europe provide:

» IT Support Services and Products
» Bespoke Software Development


Contact our Swindon office on:
+44 (0)1793 614 700
to discuss your IT needs.


CLOSE IT
Emnico Logo
Your Virtual Technology Team
Delivering Peak Performance
Category: Type: Order:
Search For:  
Home > Library > Get Windows Key

Get Windows Key

This script will retrieve the Windows product key from any Windows machine.
Added 334 days ago by Emnico
Download
Review
Back
101Views
This script has been successfully tested by Emnico and is verified to be working.

Source code

' Find Product Activation Key on Remote Machine
' Got this from a posting by 'Alatar1' at www.theeldergeek.com
'
' I just added the inputbox - Rob

If Wscript.Arguments.Count = 0 Then
    strComputer = inputbox("Enter a computer name to query the Windows product key from","Enter computer name")
    if strComputer = "" then wscript.quit
Else
    strCOmputer = Wscript.Arguments.Item(0)

End If

Dim Digits (24)
Digits (0) = "B" : Digits (1) = "C": Digits (2) = "D": Digits (3) = "F":
Digits (4) = "G": Digits (5) = "H": Digits (6) = "J": Digits (7) = "K":
Digits (8) = "M": Digits (9) = "P": Digits (10) = "Q": Digits (11) = "R":
Digits (12) = "T": Digits (13) = "V": Digits (14) = "W": Digits (15) = "X":
Digits (16) = "Y": Digits (17) = "2": Digits (18) = "3": Digits (19) = "4":
Digits (20) = "6" : Digits (21) = "7" : Digits (22) = "8": Digits (23) = "9"

Dim HexBuf (100), HexDigitalPID (15)
Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")

objReg.GetBinaryValue &H80000002, "SOFTWARE\Microsoft\Windows NT\CurrentVersion\", "DigitalProductId", HexBuf

' Extract Relevant Section of Digital Product ID
StartOffset = 52 : EndOffset =67
For i = StartOffset to EndOffset
  HexDigitalPID (i-StartOffset) = HexBuf(i)
next

' Convert Encoded Product ID to Activation Key
dLen = 29 : sLen = 15
KEYSTRING =""
for i=dLen-1 to 0 step -1
  if ((i + 1) mod 6) = 0 then
    KEYSTRING = KEYSTRING & "-" 
  else
    HN = 0
    For N = (sLen -1) to 0 step -1
      Value = ( (HN *2^8 ) Or HexDigitalPID (N))
      HexDigitalPID (N) = Value \ 24
      HN = (Value mod 24)
    next
    KEYSTRING = KEYSTRING & Digits(HN)
  end if
next
KEYSTRING2 = StrReverse (KEYSTRING)
WScript.Echo KEYSTRING2


| Privacy policy | Environmental policy | Site map |