SwarupSaha

Get Product Key

Jan 8th, 2016
451
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Explicit
  2.  
  3. Dim objshell,path,DigitalID, Result
  4. Set objshell = CreateObject("WScript.Shell")
  5. 'Set registry key path
  6. Path = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\"
  7. 'Registry key value
  8. DigitalID = objshell.RegRead(Path & "DigitalProductId")
  9. Dim ProductName,ProductID,ProductKey,ProductData
  10. 'Get ProductName, ProductID, ProductKey
  11. ProductName = "Product Name: " & objshell.RegRead(Path & "ProductName")
  12. ProductID = "Product ID: " & objshell.RegRead(Path & "ProductID")
  13. ProductKey = "Installed Key: " & ConvertToKey(DigitalID)
  14. ProductData = ProductName  & vbNewLine & ProductID  & vbNewLine & ProductKey
  15. 'Show messbox if save to a file
  16. If vbYes = MsgBox(ProductData  & vblf & vblf & "Save to a file?", vbYesNo + vbQuestion, "BackUp Windows Key Information") then
  17.    Save ProductData
  18. End If
  19.  
  20.  
  21.  
  22. 'Convert binary to chars
  23. Function ConvertToKey(Key)
  24.     Const KeyOffset = 52
  25.     Dim isWin8, Maps, i, j, Current, KeyOutput, Last, keypart1, insert
  26.     'Check if OS is Windows 8
  27.    isWin8 = (Key(66) \ 6) And 1
  28.     Key(66) = (Key(66) And &HF7) Or ((isWin8 And 2) * 4)
  29.     i = 24
  30.     Maps = "BCDFGHJKMPQRTVWXY2346789"
  31.     Do
  32.         Current= 0
  33.         j = 14
  34.         Do
  35.            Current = Current* 256
  36.            Current = Key(j + KeyOffset) + Current
  37.            Key(j + KeyOffset) = (Current \ 24)
  38.            Current=Current Mod 24
  39.             j = j -1
  40.         Loop While j >= 0
  41.         i = i -1
  42.         KeyOutput = Mid(Maps,Current+ 1, 1) & KeyOutput
  43.         Last = Current
  44.     Loop While i >= 0
  45.     keypart1 = Mid(KeyOutput, 2, Last)
  46.     insert = "N"
  47.     KeyOutput = Replace(KeyOutput, keypart1, keypart1 & insert, 2, 1, 0)
  48.     If Last = 0 Then KeyOutput = insert & KeyOutput
  49.     ConvertToKey = Mid(KeyOutput, 1, 5) & "-" & Mid(KeyOutput, 6, 5) & "-" & Mid(KeyOutput, 11, 5) & "-" & Mid(KeyOutput, 16, 5) & "-" & Mid(KeyOutput, 21, 5)
  50.    
  51.    
  52. End Function
  53. 'Save data to a file
  54. Function Save(Data)
  55.     Dim fso, fName, txt,objshell,UserName
  56.     Set objshell = CreateObject("wscript.shell")
  57.     'Get current user name
  58.    UserName = objshell.ExpandEnvironmentStrings("%UserName%")
  59.     'Create a text file on desktop
  60.    fName = "C:\Users\" & UserName & "\Desktop\WindowsKeyInfo.txt"
  61.     Set fso = CreateObject("Scripting.FileSystemObject")
  62.     Set txt = fso.CreateTextFile(fName)
  63.     txt.Writeline Data
  64.     txt.Close
  65. End Function
Add Comment
Please, Sign In to add comment