Jump to content

Windows and Office key


JFX
 Share

Recommended Posts

  • Moderators

Hi. Is it possible to adapt this script to get Windows keys from non-local machines on a business network. Thanks in advance.

 

You should be able to simply add the remote machine before the reg call. This:

$bKey = RegRead("HKLM64\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "DigitalProductId")

Becomes this:

$bKey = RegRead("\\RemoteMachine\HKLM64\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "DigitalProductId")

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

I tested the script on Office 2013 but it gives a wrong result

You can check the last five digits with  cscript.exe OSPP.VBS  /dstatus the script is available in the office installation folder

Your right Office 2013 gives wrong result. I'm removed it for now to avoid confusion.

Link to comment
Share on other sites

  • Moderators

Thank you JLogan3o13. And sorry for french post. That's right, it works. The best way would be to have an inputbox to enter computer name and recording it in a variable like $StrComputer to avoid replacing computer name at each time. I'm working on it.

 

Or take in the machine name as a parameter and pass it that way. Something like "MyExe.exe /<pc name>".

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

I've modified this script to work with remote PC :

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile_x64=CleWindowsDistant.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
; ------------------------------------------------------------------------------
$StrComputer = InputBox("Windows Computer Key", "Computer name")

$GUI_Start = GUICreate("Product Key Finder", 200, 120, -1, -1, BitXOR($GUI_SS_DEFAULT_GUI, $WS_MINIMIZEBOX))
$button1 = GUICtrlCreateButton(" Windows Key Search ", 27, 25, 150)
GUICtrlSetFont(-1, 10, "", "", "Tahoma")
$button2 = GUICtrlCreateButton(" Office Key Search ", 27, 65, 150)
GUICtrlSetFont(-1, 10, "", "", "Tahoma")
GUISetState()

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $button1
MsgBox(0, "Available Windows Licence Keys", "Windows Key : " & @TAB & @TAB & _DecodeProductKey("Windows") & @CRLF & @CRLF & _
"Windows Key DPid4 : " & @TAB & _DecodeProductKey("Windows_DPid4") & @CRLF & @CRLF & _
"Windows Default : " & @TAB & _DecodeProductKey("Windows_Def") & @CRLF & @CRLF & _
"Windows Default DPid4 : " & @TAB & _DecodeProductKey("Windows_Def_DPid4"))
Case $button2
MsgBox(0, "Available Office Licence Keys", "Office XP Key : " & @TAB & @TAB & _DecodeProductKey("Office XP") & @CRLF & @CRLF & _
"Office 2003 Key : " & @TAB & @TAB & _DecodeProductKey("Office 2003") & @CRLF & @CRLF & _
"Office 2007 Key : " & @TAB & @TAB & _DecodeProductKey("Office 2007") & @CRLF & @CRLF & _
"Office 2010 x86 Key: " & @TAB & _DecodeProductKey("Office 2010 x86") & @CRLF & @CRLF & _
"Office 2010 x64 Key: " & @TAB & _DecodeProductKey("Office 2010 x64"))
EndSwitch
WEnd

Func _DecodeProductKey($Product)
Local $bKey[15], $sKey[29], $Digits[24], $Value = 0, $hi = 0, $n = 0, $i = 0, $dlen = 29, $slen = 15, $Result, $BinaryDPID, $KeyPos = 0x34 * 2 + 3, $RegKey

$Digits = StringSplit("BCDFGHJKMPQRTVWXY2346789", "")

Switch $Product

Case "Windows"
$BinaryDPID = RegRead("\\" & $StrComputer & "\HKLM64\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "DigitalProductId")
Case "Windows_DPid4"
$BinaryDPID = RegRead("\\" & $StrComputer & "\HKLM64\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "DigitalProductId4")
$KeyPos = 0x328 * 2 + 3
Case "Windows_Def"
$BinaryDPID = RegRead("\\" & $StrComputer & "\HKLM64\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DefaultProductKey", "DigitalProductId")
Case "Windows_Def_DPid4"
$BinaryDPID = RegRead("\\" & $StrComputer & "\HKLM64\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DefaultProductKey", "DigitalProductId4")
$KeyPos = 0x328 * 2 + 3


Case "Office XP"
$RegKey = "\\" & $StrComputer & "\HKLM\SOFTWARE\Microsoft\Office\10.0\Registration"
If @OSArch = 'x64' Then $RegKey = "\\" & $StrComputer & "\HKLM64\SOFTWARE\Wow6432Node\Microsoft\Office\10.0\Registration"
For $i = 1 To 100
$var = RegEnumKey($RegKey, $i)
If @error <> 0 Then ExitLoop
$BinaryDPID = RegRead($RegKey & '\' & $var, 'DigitalProductId')
If Not @error Then ExitLoop
Next


Case "Office 2003"
$RegKey = "\\" & $StrComputer & "\HKLM\SOFTWARE\Microsoft\Office\11.0\Registration"
If @OSArch = 'x64' Then $RegKey = "\\" & $StrComputer & "\HKLM64\SOFTWARE\Wow6432Node\Microsoft\Office\11.0\Registration"
For $i = 1 To 100
$var = RegEnumKey($RegKey, $i)
If @error <> 0 Then ExitLoop
$BinaryDPID = RegRead($RegKey & '\' & $var, 'DigitalProductId')
If Not @error Then ExitLoop
Next


Case "Office 2007"
$RegKey = "\\" & $StrComputer & "\HKLM\SOFTWARE\Microsoft\Office\12.0\Registration"
If @OSArch = 'x64' Then $RegKey = "\\" & $StrComputer & "\HKLM64\SOFTWARE\Wow6432Node\Microsoft\Office\12.0\Registration"
For $i = 1 To 100
$var = RegEnumKey($RegKey, $i)
If @error <> 0 Then ExitLoop
$BinaryDPID = RegRead($RegKey & '\' & $var, 'DigitalProductId')
If Not @error Then ExitLoop
Next


Case "Office 2010 x86"
$RegKey = "\\" & $StrComputer & "\HKLM\SOFTWARE\Microsoft\Office\14.0\Registration"
If @OSArch = 'x64' Then $RegKey = "\\" & $StrComputer & "\HKLM64\SOFTWARE\Wow6432Node\Microsoft\Office\14.0\Registration"
For $i = 1 To 100
$var = RegEnumKey($RegKey, $i)
If @error <> 0 Then ExitLoop
$BinaryDPID = RegRead($RegKey & '\' & $var, 'DigitalProductId')
If Not @error Then ExitLoop
Next
$KeyPos = 0x328 * 2 + 3


Case "Office 2010 x64"
If @OSArch <> 'x64' Then SetError(1, 0, "Product not found")
$RegKey = "\\" & $StrComputer & "\HKLM64\SOFTWARE\Microsoft\Office\14.0\Registration"
For $i = 1 To 100
$var = RegEnumKey($RegKey, $i)
If @error <> 0 Then ExitLoop
$BinaryDPID = RegRead($RegKey & '\' & $var, 'DigitalProductId')
If Not @error Then ExitLoop
Next
$KeyPos = 0x328 * 2 + 3


Case Else
Return SetError(1, 0, "Product not supported")

EndSwitch

If StringLen($BinaryDPID) < 29 Then Return SetError(1, 0, "Product not found")


$BinaryDPID = StringMid($BinaryDPID, $KeyPos)


For $i = 1 To 29 Step 2
$bKey[Int($i / 2)] = Dec(StringMid($BinaryDPID, $i, 2))
Next

For $i = $dlen - 1 To 0 Step -1
If Mod(($i + 1), 6) = 0 Then
$sKey[$i] = "-"
Else
$hi = 0
For $n = $slen - 1 To 0 Step -1
$Value = BitOR(BitShift($hi, -8), $bKey[$n])
$bKey[$n] = Int($Value / 24)
$hi = Mod($Value, 24)
Next
$sKey[$i] = $Digits[$hi + 1]
EndIf

Next
For $i = 0 To 28
$Result = $Result & $sKey[$i]
Next

Return $Result

EndFunc ;==>_DecodeProductKey
It works with my laptop but not with others Windows7 PC.

Any idea ?

Edited by Melba23
Added code tags
Link to comment
Share on other sites

  • Moderators

loloplat, it looks like your keyboard barfed - can you please surround your code in a proper code block. Help us help you.

post-54985-0-03317400-1379942242_thumb.p

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • 8 months later...

@JFX I'm having trouble getting the Office 2013 keys, on the two PCs I've tried neither of them return any key for 2013. But for some reason they return the same key under Office 2010? Any ideas? Thanks.

Link to comment
Share on other sites

@BPDIT Well, you can take a look in the registry, there should be a DigitalProductId somewhere in the subykey of SOFTWAREMicrosoftOffice15.0Registration

There was a missing "return" before SetError(1, 0, "Product not found"), so x64 products would show the same key on x86 OS.

Link to comment
Share on other sites

  • 6 months later...

On some computers I notice there is no DigitalProductId in the SOFTWAREMicrosoftOffice14.0Registration section.  In this case the script does not work.  But this computer I am on now has an activated copy of Office 2010 Professional Plus on it. 

Has anyone else had this issue?  Any ideas how to fix this?

Even Produkey fails to get the product key from this machine.

I went ahead and exported the reg file for SOFTWAREMicrosoftOffice and SOFTWAREWow6432NodeMicrosoftOffice just in case anyone needs to see it to verify.  I cam PM the file to you if you think you may be able to figure this out.

I'm completely at a loss as to why there is no DigitalProductId. 

Edited by Proph
Link to comment
Share on other sites

  • 8 months later...

@JFX

Could you please update the offline version in post #30 work with windows 8 and office 2013?

The code has changed quite a lot since. I have been thinking to change it myself, but the code has changed substantially from this to this and am scratching my head how i could update it

Func _Base24_Decode($BinaryDPID)
 
Local $bKey[15], $sKey[29], $Digits[24], $Value = 0, $hi = 0, $n = 0, $i = 0, $dlen = 29, $slen = 15, $Result
$Digits = StringSplit("BCDFGHJKMPQRTVWXY2346789", "")
 
For $i = 1 To 29 Step 2
$bKey[Int($i / 2)] = Dec(StringMid($BinaryDPID, $i, 2))
Next
 
For $i = $dlen - 1 To 0 Step -1
If Mod(($i + 1), 6) = 0 Then
$sKey[$i] = "-"
Else
$hi = 0
For $n = $slen - 1 To 0 Step -1
$Value = BitOR(BitShift($hi, -8), $bKey[$n])
$bKey[$n] = Int($Value / 24)
$hi = Mod($Value, 24)
Next
$sKey[$i] = $Digits[$hi + 1]
EndIf
Next
 
For $i = 0 To 28
$Result = $Result & $sKey[$i]
Next
 
IF $Result = "BBBBB-BBBBB-BBBBB-BBBBB-BBBBB" Then $Result = ""
 
Return $Result

 

new detection for windows 8 and office 2013

If Not BinaryLen($bKey) Then Return ""

    Local $aKeys[BinaryLen($bKey)]
    For $i = 0 To UBound($aKeys) - 1
        $aKeys[$i] = Int(BinaryMid($bKey, $i + 1, 1))
    Next
    Local Const $isWin8 = BitAND(BitShift($aKeys[$iKeyOffset + 14], 3), 1)
    $aKeys[$iKeyOffset + 14] = BitOR(BitAND($aKeys[$iKeyOffset + 14], 0xF7), BitShift(BitAND($isWin8, 2), -2))
    $i = 24
    Local $sChars = "BCDFGHJKMPQRTVWXY2346789", $iCur, $iX, $sKeyOutput, $iLast
    While $i > -1
        $iCur = 0
        $iX = 14
        While $iX > -1
            $iCur = BitShift($iCur, -8)
            $iCur = $aKeys[$iX + $iKeyOffset] + $iCur
            $aKeys[$iX + $iKeyOffset] = Int($iCur / 24)
            $iCur = Mod($iCur, 24)
            $iX -= 1
        WEnd
        $i -= 1
        $sKeyOutput = StringMid($sChars, $iCur + 1, 1) & $sKeyOutput
        $iLast = $iCur
    WEnd
    If $isWin8 Then
        $sKeyOutput = StringMid($sKeyOutput, 2, $iLast) & "N" & StringTrimLeft($sKeyOutput, $iLast + 1)
    EndIf

    Return StringRegExpReplace($sKeyOutput, '(\w{5})(\w{5})(\w{5})(\w{5})(\w{5})', '\1-\2-\3-\4-\5')

Link to comment
Share on other sites

  • 4 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...