I've just started working on a task assigned to me by the IT department at work, to create a program that can read the product keys used to install Microsoft Office 2013 and assign it to the computer name, so they can store it in a database in case of recovery being needed (bear in mind this is a company with over 150 systems).

I've checked through the net to find a few suggested programs to get the product key, and then I've delved into making the program myself using both AutoIT and VB.net.

The system I'm testing this program on has Microsoft Business Retail edition installed, and running C:\Program Files(x86)\Microsoft Office\Office15\ cscript ospp.vbs has provided me with two 5-character keys - one for Microsoft Project (BWTM4) and one for Office 2013 (7PYM4). When I run my applications that I've created, I get a key with the BWMT4 key, and the applications from the net (Belarc, SterJo, etc.) return the same key. But again, this is the key for Project and Microsoft Office 2013 installation verifies this with the message : This key is for Microsoft Project 2013.

My AutoIT code:

Case "Office 2013 x86"
        $RegKey = 'HKLM\SOFTWARE\Microsoft\Office\15.0\Registration'
        If @OSArch = 'x64' Then $RegKey = 'HKLM64\SOFTWARE\Wow6432Node\Microsoft\Office\15.0\Registration'
        For $i = 1 To 1024
            $var = RegEnumKey($RegKey, $i)
            If @error <> 0 Then ExitLoop
            $bKey = RegRead($RegKey & '\' & $var, 'DigitalProductId')
            If Not @error Then ExitLoop
        $iKeyOffset = 0x328

Case "Office 2013 x64"
        If @OSArch <> 'x64' Then SetError(1, 0, "Product not found")
        $RegKey = 'HKLM64\SOFTWARE\Microsoft\Office\15.0\Registration'
        For $i = 1 To 1024
            $var = RegEnumKey($RegKey, $i)
            If @error <> 0 Then ExitLoop
            $bKey = RegRead($RegKey & '\' & $var, 'DigitalProductId')
            If Not @error Then ExitLoop
        $iKeyOffset = 0x328

My VB.net code: This code is based on that from the net, not taking claim to making this

        Dim digitalProductId As IList(Of Byte) = Nothing
            If True Then
                Dim registry As RegistryKey = Nothing
                registry = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64).OpenSubKey("SOFTWARE\Wow6432Node\Microsoft\Office\15.0\Registration\{90150000-012D-0000-0000-0000000FF1CE}", False)
            If registry IsNot Nothing Then
                digitalProductId = TryCast(registry.GetValue("DigitalProductId"), Byte())
                Return Nothing
            End If
        End If

        Dim keyStartIndex As Integer = 52
        Dim keyEndIndex As Integer = keyStartIndex + 15

Now, is there a different starting index for the Office 2013 key or is it overwritten by Lync 2013's key/Project 2013's key? Or am I going about this the completely wrong way?

Really needing help with this, if anyone can assist that would be great.


The code below displays the Product Key for the Windows OS. But it uses the exact same principle to attain the Office Key. The key is obtained from the Windows Registry. Locate the registry and assign it to the code and it should work fine :)

Public Function GetProductKey(ByVal KeyPath As String, ByVal ValueName As String) As String

    Dim HexBuf As Object = My.Computer.Registry.GetValue(KeyPath, ValueName, 0)

    If HexBuf Is Nothing Then Return "N/A"

    Dim tmp As String = ""

    For l As Integer = LBound(HexBuf) To UBound(HexBuf)
        tmp = tmp & " " & Hex(HexBuf(l))

    Dim StartOffset As Integer = 52
    Dim EndOffset As Integer = 67
    Dim Digits(24) As String

    Digits(0) = "B" : Digits(1) = "C" : Digits(2) = "D" : Digits(3) = "F"
    Digits(4) = "G" : Digits(5) = "H" : Digits(6) = "J" : Digits(7) = "K"
    Digits(8) = "M" : Digits(9) = "P" : Digits(10) = "Q" : Digits(11) = "R"
    Digits(12) = "T" : Digits(13) = "V" : Digits(14) = "W" : Digits(15) = "X"
    Digits(16) = "Y" : Digits(17) = "2" : Digits(18) = "3" : Digits(19) = "4"
    Digits(20) = "6" : Digits(21) = "7" : Digits(22) = "8" : Digits(23) = "9"

    Dim dLen As Integer = 29
    Dim sLen As Integer = 15
    Dim HexDigitalPID(15) As String
    Dim Des(30) As String

    Dim tmp2 As String = ""

    For i = StartOffset To EndOffset
        HexDigitalPID(i - StartOffset) = HexBuf(i)
        tmp2 = tmp2 & " " & Hex(HexDigitalPID(i - StartOffset))

    Dim KEYSTRING As String = ""

    For i As Integer = dLen - 1 To 0 Step -1
        If ((i + 1) Mod 6) = 0 Then
            Des(i) = "-"
            KEYSTRING = KEYSTRING & "-"
            Dim HN As Integer = 0
            For N As Integer = (sLen - 1) To 0 Step -1
                Dim Value As Integer = ((HN * 2 ^ 8) Or HexDigitalPID(N))
                HexDigitalPID(N) = Value \ 24
                HN = (Value Mod 24)


            Des(i) = Digits(HN)
            KEYSTRING = KEYSTRING & Digits(HN)
        End If

    Return StrReverse(KEYSTRING)

End Function

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Label1.Text = GetProductKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\", "DigitalProductId")
End Sub
  • 1
    Hey James, thanks for your reply. I have this in a separate function that is called, and it matches to the registry location of Office 2013. However, I've had mixed results. On a system with 2013 installed, I retrieved a key that was identified as a Microsoft Project 2013 key 'ONLY'. It wouldn't work for the Office Suite. On a system with no 2013 installed, it returned a key for Microsoft Lync 2013. And on a system with Professional 2013 installed, it returned the same Lync key, as that on the other system. Confusing, huh? D: – DeeKayy90 Mar 26 '14 at 8:43
  • 1
    Confusing indeed :) I will have a tinker around and will get back to you! – James Mar 26 '14 at 8:55
  • 1
    What I have noticed is that {90150000-012D-0000-0000-0000000FF1CE} can change from PC to PC, I would check a few of your companies PC's and see if this address is the same on all of them. If its not then that would be your problem. I have checked a few of the PC's in my workplace and some of them vary slightly. Hope that helps. – James Mar 26 '14 at 9:55
  • 1
    Hi James. I manually changed the hard coded registry location accordingly for 5 different PCs and was hitting roadblocks even then. The 5th PC didnt even have the 90150000 - rather it had 91150000, and had two of these folders with the DigitalProductId. I tested for both to no avail. Seems like 2013 remains out of reach for me. I will give it another shot tomorrow and report my results. Thanks again. – DeeKayy90 Mar 26 '14 at 13:14
  • I have found this: dropbox.com/s/7sq18lcsllvzsxs/… - Didn't work for me, but uses a different method which might be of interest, I am going to look at fixing it now. – James Mar 26 '14 at 13:30

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.