March 21, 2013

Retrieve your SharePoint Product key from server [2007 / 2010 / 2013]

Hi,

here is the below script which can retrieve your SharePoint product key from the machine, tested in Dev server (SharePoint 2010 version). i hope this may help in some situations for you:


const HKEY_LOCAL_MACHINE = &H80000002
strKeyPath = "SOFTWARE\Microsoft\Office\14.0\Registration\{90140000-110D-0000-1000-0000000FF1CE}"
strValueName = "DigitalProductId"
strComputer = "."
dim iValues()
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
oReg.GetBinaryValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,iValues
Dim arrDPID
arrDPID = Array()
For i = 808 to 822
ReDim Preserve arrDPID( UBound(arrDPID) + 1 )
arrDPID( UBound(arrDPID) ) = iValues(i)
Next

Dim arrChars
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")

For i = 24 To 0 Step -1
k = 0
For j = 14 To 0 Step -1
k = k * 256 Xor arrDPID(j)
arrDPID(j) = Int(k / 24)
k = k Mod 24
Next
strProductKey = arrChars(k) & strProductKey
If i Mod 5 = 0 And i <> 0 Then strProductKey = "-" & strProductKey
Next
strFinalKey = strProductKey

Set wshShell=CreateObject("wscript.shell")
strPopupMsg = "Your Microsoft SharePoint 2010 Product Key is:" & vbNewLine & vbNewLine & strFinalKey
strPopupTitle = "Product Key"
wshShell.Popup strPopupMsg,,strPopupTitle,vbCancelOnly+vbinformation
wScript.Echo strPopupMsg



save its as sharepointlicense.vbs and run it from command prompt.

Thanks,
JK

Update after Suggesting Salaudeen with his Power Shell script for 2007 & 2010 version SharePoint Farm as below:

PowerShell Script to Recover SharePoint 2007 Product key:
function Get-SP2007ProductKey {   
    $map="BCDFGHJKMPQRTVWXY2346789"
    $value = (get-itemproperty "HKLM:\SOFTWARE\Microsoft\Office\12.0\Registration\{90120000-110D-0000-1000-0000000FF1CE}").digitalproductid[0x34..0x42] 
    $ProductKey = "" 
    for ($i = 24; $i -ge 0; $i--) {
      $r = 0
      for ($j = 14; $j -ge 0; $j--) {
        $r = ($r * 256) -bxor $value[$j]
        $value[$j] = [math]::Floor([double]($r/24))
        $r = $r % 24
      }
      $ProductKey = $map[$r] + $ProductKey
      if (($i % 5) -eq 0 -and $i -ne 0) {
        $ProductKey = "-" + $ProductKey
      }
    }
    $ProductKey
}

#Call the function

Get-SP2007ProductKey

PowerShell Script to Recover SharePoint 2010 Product Key:
function Get-SP2010ProductKey {   
    $map="BCDFGHJKMPQRTVWXY2346789"
    $value = (get-itemproperty "HKLM:\SOFTWARE\Microsoft\Office\14.0\Registration\{90140000-110D-0000-1000-0000000FF1CE}").digitalproductid[0x34..0x42] 
    $ProductKey = "" 
    for ($i = 24; $i -ge 0; $i--) {
      $r = 0
      for ($j = 14; $j -ge 0; $j--) {
        $r = ($r * 256) -bxor $value[$j]
        $value[$j] = [math]::Floor([double]($r/24))
        $r = $r % 24
      }
      $ProductKey = $map[$r] + $ProductKey
      if (($i % 5) -eq 0 -and $i -ne 0) {
        $ProductKey = "-" + $ProductKey
      }
    }
    $ProductKey
}
#Call the function
Get-SP2010ProductKey

Update from Senglory  as a comment to my blog post: 03/01/14 

And here's the code for Sharepoint 2013

function Get-SP2013ProductKey { 
$map="BCDFGHJKMPQRTVWXY2346789" 
$value = (get-itemproperty "HKLM:\SOFTWARE\Microsoft\Office\15.0\Registration\{90150000-110D-0000-1000-0000000FF1CE}").digitalproductid[0x34..0x42] 
$ProductKey = "" 
for ($i = 24; $i -ge 0; $i--) { 
$r = 0 
for ($j = 14; $j -ge 0; $j--) { 
$r = ($r * 256) -bxor $value[$j] 
$value[$j] = [math]::Floor([double]($r/24)) 
$r = $r % 24 

$ProductKey = $map[$r] + $ProductKey 
if (($i % 5) -eq 0 -and $i -ne 0) { 
$ProductKey = "-" + $ProductKey 


$ProductKey

#Call the function
Get-SP2013ProductKey


[And still i haven't tried this as i don't have 2013 version environment, if it works please do reply your confirmation]

9 comments:

  1. You can Recover SharePoint 2007 / 2010 Product Key using PowerShell. Here is the Script:

    http://www.sharepointdiary.com/2013/07/recover-sharepoint-2007-2010-product-key.html#ixzz2adRukrTR

    ReplyDelete
    Replies
    1. Thank you Saladeen, i will append these Power Shell script at my post. :)

      Delete
  2. Nice trick! I have recovered my Office product key using KeyFinder Plus.

    ReplyDelete
  3. And here's the code for Sharepoint 2013

    function Get-SP2013ProductKey {
    $map="BCDFGHJKMPQRTVWXY2346789"
    $value = (get-itemproperty "HKLM:\SOFTWARE\Microsoft\Office\15.0\Registration\{90150000-110D-0000-1000-0000000FF1CE}").digitalproductid[0x34..0x42]
    $ProductKey = ""
    for ($i = 24; $i -ge 0; $i--) {
    $r = 0
    for ($j = 14; $j -ge 0; $j--) {
    $r = ($r * 256) -bxor $value[$j]
    $value[$j] = [math]::Floor([double]($r/24))
    $r = $r % 24
    }
    $ProductKey = $map[$r] + $ProductKey
    if (($i % 5) -eq 0 -and $i -ne 0) {
    $ProductKey = "-" + $ProductKey
    }
    }
    $ProductKey
    }
    #Call the function
    Get-SP2013ProductKey

    ReplyDelete
    Replies
    1. Hi Senglory,

      Thanks for your update with version 2013, i will update it to my post.

      Thanks,
      JK

      Delete
    2. Hi CPfenn,

      i tested in my SharePoint 2013 environment, it was retriving a key which was not entered by me during installation.

      if i found a right way i will surly update.

      Thanks,
      Jk

      Delete
  4. #This one should work SP-2013
    function Get-SP2013ProductKey {
    $map="BCDFGHJKMPQRTVWXY2346789"
    $value = (get-itemproperty "HKLM:\SOFTWARE\Microsoft\Office\15.0\Registration\{90150000-110D-0000-1000-0000000FF1CE}").digitalproductid
    $baseAddress = 808
    $needsN = ($value[$baseAddress + 14] -shl 3) -and 1;

    $ProductKey = ""
    for ($i = 24; $i -ge 0; $i--) {
    $r = 0
    for ($j = 13; $j -ge 0; $j--) {
    $test = $value[$baseAddress + $j]
    $r = ($r * 256) -bxor $value[$baseAddress + $j]
    $floor = [math]::Floor([double]($r/24))
    $value[$baseAddress + $j] = $floor
    $r = $r % 24
    }
    $ProductKey = $map[$r] + $ProductKey
    }

    if($needsN)
    {
    $firstLetterIndex = 0

    for ($i = 0; $i -lt $ProductKey.Length; $i++) {
    if($ProductKey[0] -eq $map[$i])
    {
    $firstLetterIndex = $i
    break
    }
    }

    $ProductKeyWithN = $ProductKey = $ProductKey.substring(1) # Remove first character
    $ProductKeyWithN = $ProductKeyWithN.SubString(0, $firstLetterIndex) + "N" + $ProductKeyWithN.SubString($firstLetterIndex)
    $ProductKeyWithN = $ProductKeyWithN.SubString(0, 5) + "-" + $ProductKeyWithN.SubString(5, 5) + "-" + $ProductKeyWithN.SubString(10, 5) + "-" + $ProductKeyWithN.SubString(15, 5) + "-" + $ProductKeyWithN.SubString(20, 5)
    }
    $ProductKeyWithN
    }
    Get-SP2013ProductKey

    PAUSE

    ReplyDelete