1. ' VBS Script to get the Windows(R) 7 Product Key from a PC's registry.
  2.  
  3. '
  4.  
  5. ' Save the VBScript as "getWin7Key.vbs" somewhere on your Windows7 PC.
  6.  
  7. ' Now, when you double-click the local script file an alertbox pops up
  8.  
  9. ' displaying the product key stored in the machine's Windows registry.
  10.  
  11.  
  12.  
  13.  
  14. Set WshShell = WScript.CreateObject("WScript.Shell")
  15.  
  16.  
  17.  
  18.  
  19. KeyPath = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DigitalProductId"
  20.  
  21. MsgBox ExtractKey(WshShell.RegRead(KeyPath))
  22.  
  23.  
  24.  
  25.  
  26. Function ExtractKey(KeyInput)
  27.  
  28.     Const KeyOffset = 52
  29.  
  30.     i = 28
  31.  
  32.     CharWhitelist = "BCDFGHJKMPQRTVWXY2346789"
  33.  
  34.     Do
  35.  
  36.         Cur = 0
  37.  
  38.         x = 14
  39.  
  40.         Do
  41.  
  42.             Cur = Cur * 256
  43.  
  44.             Cur = KeyInput(x + KeyOffset) + Cur
  45.  
  46.             KeyInput(x + KeyOffset) = (Cur \ 24) And 255
  47.  
  48.             Cur = Cur Mod 24
  49.  
  50.             x = x -1
  51.  
  52.         Loop While x >= 0
  53.  
  54.         i = i -1
  55.  
  56.         KeyOutput = Mid(CharWhitelist, Cur + 1, 1) & KeyOutput
  57.  
  58.         If (((29 - i) Mod 6) = 0) And (i <> -1) Then
  59.  
  60.             i = i -1
  61.  
  62.             KeyOutput = "-" &amp; KeyOutput
  63.  
  64.         End If
  65.  
  66.     Loop While i >= 0
  67.  
  68.     ExtractKey = KeyOutput
  69.  
  70. End Function