1

In C#, I'm trying to obtain the value of a registry key. It is a binary key. The code I'm using

RegistryKey regKey = Registry.LocalMachine;
            regKey = regKey.OpenSubKey(@"Software\Wow6432Node\Bohemia Interactive Studio\ArmA 2 OA\");

            if (regKey != null)
            {
                string value = regKey.GetValue("KEY").ToString();
                Console.WriteLine(value);
            }
            else
            {
                return;
            }

When it writes to the console, all it outputs is System.Byte[]. How can I output the exact value of the key? What am I doing wrong?

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Decker
  • 11
  • 1

2 Answers2

2

You just cast to byte[] to get the value since your value is binary:

byte[] value = (byte[])regKey.GetValue("KEY");

To display binary, you can display in two hexadecimal digits:

 for (int i = 0; i < value.Length; i++)
     Console.Write(" {0:X2}", value[i]);
cuongle
  • 74,024
  • 28
  • 151
  • 206
  • @Decker Thus your code should not compile as you are assigning an object to a string without a cast –  Mar 29 '13 at 06:50
0

The value you get from regKey.GetValue("KEY") might be a byte array.

Please consider convert it to HEX like this article

Community
  • 1
  • 1
J.C
  • 633
  • 1
  • 13
  • 27