9 Replies - 3385 Views - Last Post: 30 June 2013 - 11:53 AM Rate Topic: -----

#1 kyle_denney  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 111
  • Joined: 10-August 12

Trying To Get Windows Product Key

Posted 25 August 2012 - 02:10 PM

I am trying to get Windows Product Key for an app that gets general computer information for computer technicians who are working remotely or locally for any size corporation. I found this code online but have run into a snag. When I try and run it the hex buffer on the first loop in the code below states that I cannot cast an integer to an array. Any ideas on how to fix this given the code or is there a better way of getting the Windows Product Key? Thank you!


im 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))
        Next

        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))
        Next

        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 & "-"
            Else
                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)

                Next

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

        Return StrReverse(KEYSTRING)

    End Function



Is This A Good Question/Topic? 0
  • +

Replies To: Trying To Get Windows Product Key

#2 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5316
  • View blog
  • Posts: 11,360
  • Joined: 02-June 10

Re: Trying To Get Windows Product Key

Posted 25 August 2012 - 03:05 PM

Quote

I cannot cast an integer to an array.

You can't. Do you know what an array is? Its a COLLECTION of some type.

So you can't cast an int to an array, but you could store an individual int in one element of an int[]

In other words

int[] anIntegerArray = 5; // Doesn't make sense. 
anIntegerArray[4] = 5; // Makes sense.  Element 4 of the array can be set equal to the value 5

This post has been edited by tlhIn`toq: 25 August 2012 - 03:05 PM

Was This Post Helpful? 0
  • +
  • -

#3 kyle_denney  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 111
  • Joined: 10-August 12

Re: Trying To Get Windows Product Key

Posted 25 August 2012 - 03:26 PM

View PosttlhIn`toq, on 25 August 2012 - 03:05 PM, said:

Quote

I cannot cast an integer to an array.

You can't. Do you know what an array is? Its a COLLECTION of some type.

So you can't cast an int to an array, but you could store an individual int in one element of an int[]

In other words

int[] anIntegerArray = 5; // Doesn't make sense. 
anIntegerArray[4] = 5; // Makes sense.  Element 4 of the array can be set equal to the value 5



Can you apply that to my code and show me how it works? I am interested in learning but I am not sure how to apply the code to the code I found. Thanks!
Was This Post Helpful? -1
  • +
  • -

#4 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10186
  • View blog
  • Posts: 37,604
  • Joined: 27-December 08

Re: Trying To Get Windows Product Key

Posted 25 August 2012 - 03:27 PM

No. It's your job to put in the effort to fix your code based on the suggestions given.
Was This Post Helpful? 0
  • +
  • -

#5 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5316
  • View blog
  • Posts: 11,360
  • Joined: 02-June 10

Re: Trying To Get Windows Product Key

Posted 25 August 2012 - 03:47 PM

If you are THAT unfamiliar then you are jumping into the designing and building of your own application from scratch, WAY too early.

First learn the language by working 2-5 "Learn C# in 30 days" type books cover to cover. Do a couple hundred on-line tutorial projects where you build what you're told to build, the way you are told to build it WITH AN EXPLANATION OF WHY so you can learn.

Then later you can start architecting your own simple stuff. Build a calculator. Build a DVD library program. Etc. Stuff that doesn't involve the complexity of a game. Then move up to games.



There are three routes people seem to take when learning programming.
  • Just start trying to create programs
  • Start taking apart other programs and try to figure out the language by reverse engineering
  • Follow a guided learning course (school or self-teaching books)


For the life of me I can't figure out why people try 1 & 2. I strongly suggest taking the guided learning approach. Those book authors go in a certain order for a reason: They know what they're doing and they know the best order to learn the materials.

Quote

Where do I start?


You start by learning a coding language FIRST.
Learn to plan before you type.
THEN you start designing software with a purpose.


If this sounds like you

Newbie/Rookie said:

I have a little programming experience but I need to write ...
read this section
Spoiler


Otherwise, you can just jump to the resources here:
Some of the tutorials below are for C# or Java not C, C++, VB.NET [...]. But the conceptual stuff of classes, object oriented design, events etc. are not language specific and should give you enough guidance in theory of program development for you to be able to look-up specific code example in your chosen coding language.



Resources, references and suggestions for new programmers. - Updated Mar 2012
Spoiler

Was This Post Helpful? 4
  • +
  • -

#6 lucky3  Icon User is offline

  • Friend lucky3 As IHelpable
  • member icon

Reputation: 231
  • View blog
  • Posts: 765
  • Joined: 19-October 11

Re: Trying To Get Windows Product Key

Posted 26 August 2012 - 05:59 AM

Couldn't agree more with what tlhIn`toq wrote.
Was This Post Helpful? 0
  • +
  • -

#7 motcom  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 290
  • View blog
  • Posts: 1,371
  • Joined: 16-June 08

Re: Trying To Get Windows Product Key

Posted 30 August 2012 - 02:16 AM

lol.. the original poster had this in vb.. now hes going c# as per suggestion...
Was This Post Helpful? 0
  • +
  • -

#8 kyle_denney  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 111
  • Joined: 10-August 12

Re: Trying To Get Windows Product Key

Posted 30 August 2012 - 05:15 AM

Thank you for all the suggestions. I do realize that having a structured learning environment is really helpful. I am currently going for my associate's degree in programming. It is not that I do not understand an array and how an array works, however, I was not sure how to fix the issue at hand. I found the code online for pulling a MS Product Key and noticed when I moved it to the IDE it was broken. I did not develop the code from scratch and therefore was not sure how to fix it. Visual Studio is notorious for giving minimal details on why something in the debugger is broken and you have to go on a rabbit trail sometimes to get to the real issue.

By the way, I do not have a problem with approaches 1 & 2 as well as 3. I have done all of them and they all have proven useful. You gain structural knowledge of programming through a school or book - however you gain a passion for programming because that is what you want to do and that is where I found myself.
Was This Post Helpful? 0
  • +
  • -

#9 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5316
  • View blog
  • Posts: 11,360
  • Joined: 02-June 10

Re: Trying To Get Windows Product Key

Posted 30 August 2012 - 07:20 AM

View Postkyle_denney, on 30 August 2012 - 06:15 AM, said:

I am currently going for my associate's degree in programming. It is not that I do not understand an array and how an array works, however, I was not sure how to fix the issue at hand.


That you are *going for* your degree is one thing. But it doesn't tell us how far you have already gone. It sounds nice, but means little. For all we know you could be on your third day of going for that degree which means you know next to nothing.

You say you understand what an array is and how it works... yet you couldn't figure out how to fix your code when you were trying to shove something other than an array into an array. Let me put it in non-coding terms. You had an engine and you were trying to state that it was a truck. That wouldn't work, would it. An engine is only PART of a truck.

Quote

Visual Studio is notorious for giving minimal details on why something in the debugger is broken and you have to go on a rabbit trail sometimes to get to the real issue.

Really? Notorious amongst whom? Your fellow first year students? Because I find it tells you exactly what is wrong. It doesn't stand up and give a lecture about why and put it into context for you with an explanation about the 25 lines of code around it. It doesn't tell telepathically intuit what you MEANT and tell you how to fix it based on your INTENT. But it does tell you exactly what the error is. And in this case it did tell you the exact problem, stopped on the offending line and said "cannot cast an integer to an array". If you don't know how to use the IDE and don't know how to look at the values in the Autos and Locals pallet, you can't blame Visual Studio. If you look at the offending line and see that one value is an integer, one is an array... look at the error... use the knowledge you have about arrays... it should be fairly clear.

Perhaps you should stop coding for an hour and work these tutorials on debugging. An hour of learning will save hundreds in frustration.

FAQ (Frequently Asked Questions - Updated July 2012




Was This Post Helpful? 0
  • +
  • -

#10 kyle_denney  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 111
  • Joined: 10-August 12

Re: Trying To Get Windows Product Key

Posted 30 June 2013 - 11:53 AM

Does anyone know how to get the WIndows 8 product key? The digitalproductid in the registry no longer exists for Windows 8.

This post has been edited by JackOfAllTrades: 30 June 2013 - 12:23 PM
Reason for edit:: Removed unnecessary quote

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1