MorganF

Windows Key

Mar 27th, 2017
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Set WshShell = CreateObject("WScript.Shell")
  2. Key = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\"
  3. DigitalID = WshShell.RegRead(key & "DigitalProductId")
  4.  
  5. ProductName = "Product Name: " & WshShell.RegRead(Key & "ProductName") & vbNewLine
  6. ProductID = "Product ID: " & WshShell.RegRead(Key & "ProductID") & vbNewLine
  7. ProductKey = "Installed Key: " & ConvertToKey(DigitalID)
  8. ProductID = ProductName & ProductID & ProductKey
  9.  
  10. If vbYes = MsgBox(ProductId & vblf & vblf & "Save to a file?", vbYesNo + vbQuestion, "Windows Key Information") then
  11.    Save ProductID
  12. End if
  13.  
  14. Function ConvertToKey(Key)
  15.     Const KeyOffset = 52
  16.     isWin8 = (Key(66) \ 6) And 1
  17.     Key(66) = (Key(66) And &HF7) Or ((isWin8 And 2) * 4)
  18.     i = 24
  19.     Chars = "BCDFGHJKMPQRTVWXY2346789"
  20.     Do
  21.         Cur = 0
  22.         X = 14
  23.         Do
  24.             Cur = Cur * 256
  25.             Cur = Key(X + KeyOffset) + Cur
  26.             Key(X + KeyOffset) = (Cur \ 24)
  27.             Cur = Cur Mod 24
  28.             X = X -1
  29.         Loop While X >= 0
  30.         i = i -1
  31.         KeyOutput = Mid(Chars, Cur + 1, 1) & KeyOutput
  32.         Last = Cur
  33.     Loop While i >= 0
  34.     If (isWin8 = 1) Then
  35.         keypart1 = Mid(KeyOutput, 2, Last)
  36.         insert = "N"
  37.         KeyOutput = Replace(KeyOutput, keypart1, keypart1 & insert, 2, 1, 0)
  38.         If Last = 0 Then KeyOutput = insert & KeyOutput
  39.     End If
  40.     a = Mid(KeyOutput, 1, 5)
  41.     b = Mid(KeyOutput, 6, 5)
  42.     c = Mid(KeyOutput, 11, 5)
  43.     d = Mid(KeyOutput, 16, 5)
  44.     e = Mid(KeyOutput, 21, 5)
  45.     ConvertToKey = a & "-" & b & "-" & c & "-" & d & "-" & e
  46. End Function
  47.  
  48. Function Save(Data)
  49.     Const ForWRITING = 2
  50.     Const asASCII = 0
  51.     Dim fso, f, fName, ts
  52.     fName = "Windows Key.txt"
  53.    Set fso = CreateObject("Scripting.FileSystemObject")
  54.     fso.CreateTextFile fName
  55.     Set f = fso.GetFile(fName)
  56.     Set f = f.OpenAsTextStream(ForWRITING, asASCII)
  57.     f.Writeline Data
  58.     f.Close
  59. End Function
Add Comment
Please, Sign In to add comment