Question Reading REG_Binary values from registry

JMcIvor

New member
Joined
Mar 28, 2013
Messages
4
Programming Experience
10+
Hi guys. New to this forum, but been in the VB world since the late 90's.

Reading from the registry is simple enough, but this is the first time I've tried to read a REG_Binary value... (99% of you just cringed and left, I'm sure)
Below is the code I'm using. From what I understand, REG_Binary values are byte strings. What I'm using doesnt seem to work:

VB.NET:
        Dim KeyBytes() As Byte = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "DigitalProductID", Nothing)
        Dim KeyValue As String = System.Text.Encoding.UTF8.GetString(KeyBytes)
        TextBox1.Text = TextBox1.Text & KeyValue

The above code returns nothing, literally. If I feed it into a msgbox, it doesnt even pop up a msgbox...

Questions you may have:
Obviously, I'm trying to decode my windows product key. I'm working on an application like magicjellybean, which returns product keys found on your system.
Yes, the key exists, this is the value it holds:
VB.NET:
I can copy but not paste it! This is truly an evasive one

Any/all help appreciated!
 
REG_Binary values are byte strings
No, they are byte arrays. Those bytes can represent anything, and you would need to know what and how to decode their meaning. If they were just strings then a string value would be used in registry. If may seem that you're after the ProductId instead, which is a string that is also part of DigitalProductID.
The above code returns nothing, literally.
Do you mean KeyBytes variable is Nothing after the GetValue call? I find it strange your debugging hasn't detected this and that you haven't been able to provide this information in your post.
If I feed it into a msgbox, it doesnt even pop up a msgbox...
The only way for that to happen is if MsgBox is not called in the first place, for example if code before that call throws an exception. Encoding.GetString will for example throw an exception if argument passed is Nothing. This is something that can happen if you're running the code in Form.Load event handler on a 64bit system, which will just swallow the exception silently. Further to that, 64bit systems have part 32/64bit registry (though most is shared or automatically redirected), you could try RegistryKey.OpenBaseKey method to open 64bit view for LocalMachine hive.
 
This is something that can happen if you're running the code in Form.Load event handler on a 64bit system, which will just swallow the exception silently.
Good call, thats exactly what I was doing!

Further to that, 64bit systems have part 32/64bit registry
Again, you are right on the money! I had to make my app compile for x64 systems and everything magically fell into place.

No, they are byte arrays. Those bytes can represent anything, and you would need to know what and how to decode their meaning. If they were just strings then a string value would be used in registry. If may seem that you're after the ProductId instead, which is a string that is also part of DigitalProductID.
Yea I'm 100% new to working with registry values that are not or can not be retrieved as string values.

The application is working beautifully, but oddly, it translates my Office 2010 key as something that is not my actual official sticker key, oddly enough. Although it returns my Win7 Ultimate key just fine. A whole new thread, I'm sure, as it is a different topic.








Thanks for the reply, you really showed how in depth your knowledge is, an asset, you are, mmmm!
yoda1y.jpg
 
Back
Top