Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. function Find-LicenseKeys{
  2.  
  3. function Search-RegistryKeyValues {
  4. param(
  5. [string]$path,
  6. [string]$valueName
  7. )
  8. Get-ChildItem $path -recurse -ea SilentlyContinue |
  9. % {
  10. if ((Get-ItemProperty -Path $_.PsPath -ea SilentlyContinue) -match $valueName)
  11. {
  12. $_.PsPath
  13. }
  14. }
  15. }
  16.  
  17. # find registry key that has value "digitalproductid"
  18. # 32-bit versions
  19. $key = Search-RegistryKeyValues "hklm:\software\microsoft\office" "digitalproductid"
  20. if ($key -eq $null) {
  21. # 64-bit versions
  22. $key = Search-RegistryKeyValues "hklm:\software\Wow6432Node\microsoft\office" "digitalproductid"
  23. if ($key -eq $null) {Write-Host "MS Office is not installed.";break}
  24. }
  25.  
  26. $valueData = (Get-ItemProperty $key).digitalproductid[52..66]
  27.  
  28. # decrypt base24 encoded binary data
  29. $productKey = ""
  30. $chars = "BCDFGHJKMPQRTVWXY2346789"
  31. for ($i = 24; $i -ge 0; $i--) {
  32. $r = 0
  33. for ($j = 14; $j -ge 0; $j--) {
  34. $r = ($r * 256) -bxor $valueData[$j]
  35. $valueData[$j] = [math]::Truncate($r / 24)
  36. $r = $r % 24
  37. }
  38. $productKey = $chars[$r] + $productKey
  39. if (($i % 5) -eq 0 -and $i -ne 0) {
  40. $productKey = "-" + $productKey
  41. }
  42. }
  43.  
  44. Write-Host "MS Office Product Key:" $productKey
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement