REG_BINARY to meaningful text

S

Srini

Hi,



Can anyone please tell me how to retrieve meaningful value from
registry value in REG_Binary type?

I tried to convert REG_Binary value to string using the following
code.

RegistryKey objKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\
\MICROSOFT\\WZCSVC\\PARAMETERS\\INTERFACES\Cheetag");

byte[] ans = (byte[])objKey.GetValue("ActiveSettings");
string sString = System.Text.Encoding.ASCII.GetString(ans);
string[] sArray = sString.Split('\0');

sString = "";
foreach (string s in sArray)
{
sString += s;
}
MessageBox.Show(sString);



sString shows some characters, which could not be understood.



How to convert the REG_BINARY value to a meaningful text? Please let
me know.

Thanks in advance
Srinivasan
 
J

Jon Skeet [C# MVP]

Srini said:
Can anyone please tell me how to retrieve meaningful value from
registry value in REG_Binary type?

You've already done it - you've got the bytes.

How to convert the REG_BINARY value to a meaningful text? Please let
me know.

That's a different question. Not all binary data has any meaningful
text representation. Suppose someone was mad enough to store a picture
in binary form in the registry - what "meaningful text" would you
expect to get out of that?
 
N

Nicholas Paldino [.NET/C# MVP]

Srini,

Assuming that you have the bytes in an array, and that you KNOW that the
bytes are going to represent text in some sort of encoding, you can use an
derivation of the Encoding class that represents the encoding of the text
and call the GetString method on it, passing the bytes to the method, and
getting a string in return.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top