I'm trying to write a small app and I want it to show the OS Install key. How can I pull this? I'm using Visual Basic 2008.

Recommended Answers

All 8 Replies

Okay, so I followed the link you provided. I got the code converted to VB.NET now and I have it inside a KeyDecoder.vb Class. Code is below. The thing is I can't quite figure out how to call it in my main form to take advantage of it. I imported the MSKeyFinder like I read to.

KeyDecoder.vb

Imports System
Imports System.Collections
Imports Microsoft.Win32

Namespace MSKeyFinder
    Public Class KeyDecoder
        Public Enum Key
            XP
            Office10
            Office11
        End Enum
        Public Shared Function GetRegistryDigitalProductId(ByVal key__1 As Key) As Byte()
            Dim digitalProductId As Byte() = Nothing
            Dim registry__2 As RegistryKey = Nothing
            Select Case key__1
                ' Open the XP subkey readonly.
                Case Key.XP
                    registry__2 = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion", False)
                    Exit Select
                    ' Open the Office 10 subkey readonly.
                Case Key.Office10
                    ' TODO: Open the registry key.
                    Exit Select
                    ' Open the Office 11 subkey readonly.
                Case Key.Office11
                    ' TODO: Open the registry key.
                    Exit Select
            End Select
            If registry__2 IsNot Nothing Then
                ' TODO: For other products, key name maybe different.
                digitalProductId = TryCast(registry__2.GetValue("DigitalProductId"), Byte())
                registry__2.Close()
            End If
            Return digitalProductId
        End Function
        Public Shared Function DecodeProductKey(ByVal digitalProductId As Byte()) As String
            ' Offset of first byte of encoded product key in
            ' 'DigitalProductIdxxx" REG_BINARY value. Offset = 34H.
            Const keyStartIndex As Integer = 52
            ' Offset of last byte of encoded product key in
            ' 'DigitalProductIdxxx" REG_BINARY value. Offset = 43H.
            Const keyEndIndex As Integer = keyStartIndex + 15
            ' Possible alpha-numeric characters in product key.
            Dim digits As Char() = New Char() {"B"c, "C"c, "D"c, "F"c, "G"c, "H"c, _
             "J"c, "K"c, "M"c, "P"c, "Q"c, "R"c, _
             "T"c, "V"c, "W"c, "X"c, "Y"c, "2"c, _
             "3"c, "4"c, "6"c, "7"c, "8"c, "9"c}
            ' Length of decoded product key
            Const decodeLength As Integer = 29
            ' Length of decoded product key in byte-form.
            ' Each byte represents 2 chars.
            Const decodeStringLength As Integer = 15
            ' Array of containing the decoded product key.
            Dim decodedChars As Char() = New Char(decodeLength - 1) {}
            ' Extract byte 52 to 67 inclusive.
            Dim hexPid As New ArrayList()
            For i As Integer = keyStartIndex To keyEndIndex
                hexPid.Add(digitalProductId(i))
            Next
            For i As Integer = decodeLength - 1 To 0 Step -1
                ' Every sixth char is a separator.
                If (i + 1) Mod 6 = 0 Then
                    decodedChars(i) = "-"c
                Else
                    ' Do the actual decoding.
                    Dim digitMapIndex As Integer = 0
                    For j As Integer = decodeStringLength - 1 To 0 Step -1
                        Dim byteValue As Integer = (digitMapIndex << 8) Or CByte(hexPid(j))
                        hexPid(j) = CByte(byteValue \ 24)
                        digitMapIndex = byteValue Mod 24
                        decodedChars(i) = digits(digitMapIndex)
                    Next
                End If
            Next
            Return New String(decodedChars)
        End Function
    End Class
End Namespace
Dim key() As Byte = MSKeyFinder.KeyDecoder.GetRegistryDigitalProductId(MSKeyFinder.KeyDecoder.Key.XP)

string resultKey= MSKeyFinder.KeyDecoder.DecodeProductKey(key)

@Adatapost - Thank you so much for the help.

In the same code that I provided above, would you happen to know how I can pull the Office Key for any version if it is installed?

You need to open appro. key

For Office 12.0 (office 2007)

Add this statement,

registry__2 = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Office\12.0\Registration\{90120000-0011-0000-0000-0000000FF1CE}", False)

When I check SOFTWARE\Microsoft\Office\12.0\ on my machine, I don't have a Registration\{90120000-0011-0000-0000-0000000FF1CE}.

I have Office 2007 installed on my computer.

Look at HKEY_LOCAL_MACHINE

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\12.0\Registration\{90120000-0011-0000-0000-0000000FF1CE}

All I have inside 12.0 is MsoExample and User Settings.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.