Results 1 to 4 of 4

Thread: [RESOLVED] DigitalProductId VB 2010 on Win7 x64

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2010
    Posts
    3

    Resolved [RESOLVED] DigitalProductId VB 2010 on Win7 x64

    Hello all!

    I have a big problem with my application!
    I must be extract a Windows DigitalProductId with VB 2010 in Windows 7 x64. I have tested a lot of code but I havn't resolved the problem... This is an easy code, it work perfectly on x86 but non on Windows 7 x64. (I havn't tested on Vista x64)


    CODE

    Code:
    ' A function that retrieves the product key used to install Windows.
        Public Function GetProductKey() As String
    
            ' This function will retreive the digital product ID from the registry
            ' and decode it into the CD key used to install a Microsoft product.
            ' All that is needed is the registry path to the digital proudct ID block
            ' for the product in question.
    
            Dim validChars() As String = {"B", "C", "D", "F", "G", "H", "J", "K", "M", _
            "P", "Q", "R", "T", "V", "W", "X", "Y", "2", _
            "3", "4", "6", "7", "8", "9"}
    
            Dim CDKey As String = ""
            Dim encodedKey(15) As Byte
            Dim digitalProductID As Byte()
            Dim dpidDataBlock As Object
    
            'Registry Path
            Const regKey As String = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\"
            ' Get the Digital Product ID data-block from the registry.
            
            '############################
            'ERROR ZONE
            'This on Win 7 x64 return =0 !!!
            dpidDataBlock = My.Computer.Registry.GetValue(regKey, "DigitalProductId", 0)
            '############################
    
            If dpidDataBlock Is Nothing Then Return "Non Rilevabile :("
    
            digitalProductID = DirectCast(dpidDataBlock, Byte())
    
            ' Extract the encoded CD key (15 bytes) from the digital product ID block.
            For n As Integer = 52 To 67
                encodedKey(n - 52) = digitalProductID(n)
            Next
    
            ' Decode the CD key.
            ' Note: The actual CD key is not stored in the registry; only the positions
            ' within the validChars() array of the characters that make up the CD key
            ' are stored and encoded.
    
            For i As Integer = 28 To 0 Step -1
                ' Calculate where the dashes are.
                If ((i + 1) Mod 6) = 0 Then
                    CDKey += " - "
                Else
                    Dim j As Integer = 0
                    For k As Integer = 14 To 0 Step -1
                        Dim Value As Integer = CInt(CLng(j * 2 ^ 8) Or encodedKey(k))
                        encodedKey(k) = CByte(Value \ 24)
                        ' Position within the validChar() array of the character to add to the CD key string.
                        j = Value Mod 24
                    Next
                    CDKey += validChars(j)
                End If
            Next
            Return StrReverse(CDKey)
    
        End Function

    ERROR:

    System.InvalidCastException:
    Unable to cast object of type 'System.Int32' to type 'System.Byte[]'.
    The variable dpidDataBlock return ZERO after Registry.GetValue



    HELP ME PLEASE !!!
    Last edited by Live; Jul 21st, 2010 at 02:23 PM. Reason: RESOLVED

  2. #2

    Re: DigitalProductId VB 2010 on Win7 x64

    1. Wrap your code in [code] tags please.
    2. You tell us the error, but you're not indicating the line that it throws the error on.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2010
    Posts
    3

    Re: DigitalProductId VB 2010 on Win7 x64

    Post Edited.

  4. #4

    Thread Starter
    New Member
    Join Date
    Jul 2010
    Posts
    3

    Resolved Re: DigitalProductId VB 2010 on Win7 x64

    I HAVED RESOLVED !!!

    I'ts very very easy!!!!

    Build the application witt Target x64 CPU or Any CPU

    Thanks to all same

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width