Posted By

hobeau on 01/29/09


Tagged

wsh


Versions (?)

Retrieve Windows Lisence key from windows using WSH


 / Published in: Visual Basic
 

URL: http://www.sythe.org/showthread.php?t=342889

  1. const HKEY_LOCAL_MACHINE = &H80000002
  2. strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion"
  3. strValueName = "DigitalProductId"
  4. strComputer = "."
  5. dim iValues()
  6. Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
  7. strComputer & "\root\default:StdRegProv")
  8. oReg.GetBinaryValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,iValues
  9. Dim arrDPID
  10. arrDPID = Array()
  11. For i = 52 to 66
  12. ReDim Preserve arrDPID( UBound(arrDPID) + 1 )
  13. arrDPID( UBound(arrDPID) ) = iValues(i)
  14. Next
  15. ' <--------------- Create an array to hold the valid characters for a microsoft Product Key -------------------------->
  16. Dim arrChars
  17. arrChars = Array("B","C","D","F","G","H","J","K","M","P","Q","R","T","V","W","X","Y","2","3","4","6","7","8","9")
  18.  
  19. ' <--------------- The clever bit !!! (Decrypt the base24 encoded binary data)-------------------------->
  20. For i = 24 To 0 Step -1
  21. k = 0
  22. For j = 14 To 0 Step -1
  23. k = k * 256 Xor arrDPID(j)
  24. arrDPID(j) = Int(k / 24)
  25. k = k Mod 24
  26. Next
  27. strProductKey = arrChars(k) & strProductKey
  28. ' <------- add the "-" between the groups of 5 Char -------->
  29. If i Mod 5 = 0 And i <> 0 Then strProductKey = "-" & strProductKey
  30. Next
  31. strFinalKey = strProductKey
  32. '
  33. ' <---------- This part of the script displays operating system Information and the license Key --------->
  34. '
  35. strComputer = "."
  36. Set objWMIService = GetObject("winmgmts:" _
  37. & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
  38. Set colOperatingSystems = objWMIService.ExecQuery _
  39. ("Select * from Win32_OperatingSystem")
  40. For Each objOperatingSystem in colOperatingSystems
  41. strOS = objOperatingSystem.Caption
  42. strBuild = objOperatingSystem.BuildNumber
  43. strSerial = objOperatingSystem.SerialNumber
  44. strRegistered = objOperatingSystem.RegisteredUser
  45. Next
  46. Set wshShell=CreateObject("wscript.shell")
  47. strPopupMsg = strOS & vbNewLine & vbNewLine
  48. strPopupMsg = strPopupMsg & "Build Number: " & strBuild & vbNewLine
  49. strPopupMsg = strPopupMsg & "PID: " & strSerial & vbNewLine & vbNewLine
  50. strPopupMsg = strPopupMsg & "Registered to: " & strRegistered & vbNewLine & vbNewLine & vbNewLine
  51. strPopupMsg = strPopupMsg & "Your Windows Product Key is:" & vbNewLine & vbNewLine & strFinalKey
  52. strPopupTitle = "Microsoft Windows License Information"
  53. wshShell.Popup strPopupMsg,,strPopupTitle,vbCancelOnly+vbinformation
  54. WScript.Quit

Report this snippet  

You need to login to post a comment.