Advertisement
Max

ComputerKey

Max
Sep 2nd, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. wmic path softwareLicensingService get OA3xOriginalProductKey
  2.  
  3. Option Explicit
  4.  
  5. Dim objshell,path,path2,DigitalID,Result,MyHostName,objWMIService,colSMBIOS,objSMBIOS
  6. Set objshell = CreateObject("WScript.Shell")
  7. 'Set registry key path
  8. Path = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\"
  9. Path2 = "HKLM\HARDWARE\DESCRIPTION\System\BIOS\"
  10. 'Registry key value
  11. DigitalID = objshell.RegRead(Path & "DigitalProductId")
  12. 'Get current computer name
  13. MyHostName = objshell.ExpandEnvironmentStrings("%ComputerName%")
  14. Set objWMIService = GetObject("winmgmts:" _
  15.     & "{impersonationLevel=impersonate}!\\" & MyHostName & "\root\cimv2")
  16. Set colSMBIOS = objWMIService.ExecQuery _
  17.     ("Select * from Win32_SystemEnclosure")
  18. For Each objSMBIOS in colSMBIOS            
  19.     SerialNumber = "Serial Number:  " & objSMBIOS.SerialNumber
  20. Next
  21. Dim ComputerName,ProductName,ProductID,ProductKey,ProductData,SerialNumber,PartNumber,ProductVersion1,ProductVersion2,ProductVersion3
  22. 'Get ProductName, ProductID, ProductKey
  23. ComputerName = "Computer Name:  " & objshell.ExpandEnvironmentStrings("%ComputerName%")
  24. ProductName = "Product Name:    " & objshell.RegRead(Path & "ProductName")
  25. ProductVersion1 = "Vers. (build):   " & objshell.RegRead(Path & "ReleaseID")
  26. ProductVersion2 = " (" & objshell.RegRead(Path & "CurrentBuild")
  27. ProductVersion3 = "." & objshell.RegRead(Path & "UBR") & ")"
  28. ProductID = "Product ID:    " & objshell.RegRead(Path & "ProductID")
  29. ProductKey = "Installed Key:    " & ConvertToKey(DigitalID)
  30.  
  31. PartNumber = "Part Number:  " & objshell.RegRead(Path2 & "SystemSKU")
  32. ProductData = ComputerName & vbNewLine & ProductName  & vbNewLine & ProductVersion1 & ProductVersion2 & ProductVersion3 & vbNewLine & ProductID  & vbNewLine & ProductKey & vbNewLine & SerialNumber & vbNewLine & PartNumber
  33. 'Show messbox if save to a file  
  34. If vbYes = MsgBox(ProductData  & vblf & vblf & "Save to a file?", vbYesNo + vbQuestion, "Back-up Windows Key Information") then
  35.    Save ProductData  
  36. End If
  37.  
  38.  
  39.  
  40. 'Convert binary to chars
  41. Function ConvertToKey(Key)
  42.     Const KeyOffset = 52
  43.     Dim isWin8, Maps, i, j, Current, KeyOutput, Last, keypart1, insert
  44.     'Check if OS is Windows 8
  45.    isWin8 = (Key(66) \ 6) And 1
  46.     Key(66) = (Key(66) And &HF7) Or ((isWin8 And 2) * 4)
  47.     i = 24
  48.     Maps = "BCDFGHJKMPQRTVWXY2346789"
  49.     Do
  50.            Current= 0
  51.         j = 14
  52.         Do
  53.            Current = Current* 256
  54.            Current = Key(j + KeyOffset) + Current
  55.            Key(j + KeyOffset) = (Current \ 24)
  56.            Current=Current Mod 24
  57.             j = j -1
  58.         Loop While j >= 0
  59.         i = i -1
  60.         KeyOutput = Mid(Maps,Current+ 1, 1) & KeyOutput
  61.         Last = Current
  62.     Loop While i >= 0  
  63.      
  64.     If (isWin8 = 1) Then
  65.         keypart1 = Mid(KeyOutput, 2, Last)
  66.         insert = "N"
  67.         KeyOutput = Replace(KeyOutput, keypart1, keypart1 & insert, 2, 1, 0)
  68.         If Last = 0 Then KeyOutput = insert & KeyOutput
  69.     End If    
  70.      
  71.  
  72.     ConvertToKey = Mid(KeyOutput, 1, 5) & "-" & Mid(KeyOutput, 6, 5) & "-" & Mid(KeyOutput, 11, 5) & "-" & Mid(KeyOutput, 16, 5) & "-" & Mid(KeyOutput, 21, 5)
  73.    
  74.      
  75. End Function
  76. 'Save data to a file
  77. Function Save(Data)
  78.     Dim fso, fName, txt,objshell,UserName,ComputerName
  79.     Set objshell = CreateObject("wscript.shell")
  80.     'Get current user name  
  81.    UserName = objshell.ExpandEnvironmentStrings("%UserName%")
  82.     'Get current computer name  
  83.    ComputerName = objshell.ExpandEnvironmentStrings("%ComputerName%")
  84.     'Create a text file on desktop  
  85.    fName = "C:\Users\" & UserName & "\Desktop\" & ComputerName & ".txt"
  86.     Set fso = CreateObject("Scripting.FileSystemObject")
  87.     Set txt = fso.CreateTextFile(fName)
  88.     txt.Writeline Data
  89.     txt.Close
  90. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement