468,783 Members | 1,656 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,783 developers. It's quick & easy.

Reading Registry using C# (System.Byte is 'binary' data value)

Reading registry:

....
RegistryKey rksub = rkey.OpenSubKey(s);
String [] valstr = rksub.GetValueNames();
foreach (String vs in valstr)
{
String vstr = rksub.GetValue(vs).ToString();
OR
String vstr = rksub.GetValue(vs);
...

call to GetValue(vs) returns "System.Byte" string if value is reg binary
entry (instead of string or DWORD).
How do you get to actual byte buffer with reg entry value returned as
"System.Byte"?
Thanks
Nov 16 '05 #1
6 15628
Try casting it:

string vstr = (string)rksub.GetValue(vs);

Robert
"John Hoffman" <news.microsoft.com> wrote in message
news:eN**************@TK2MSFTNGP12.phx.gbl...
Reading registry:

...
RegistryKey rksub = rkey.OpenSubKey(s);
String [] valstr = rksub.GetValueNames();
foreach (String vs in valstr)
{
String vstr = rksub.GetValue(vs).ToString();
OR
String vstr = rksub.GetValue(vs);
...

call to GetValue(vs) returns "System.Byte" string if value is reg binary
entry (instead of string or DWORD).
How do you get to actual byte buffer with reg entry value returned as
"System.Byte"?
Thanks

Nov 16 '05 #2
Ok,
Figured out you can cast as follows:

System.Byte[] strByte = (System.Byte[]) rksub.GetValue(vs); // This
returns buffer (say 16 byte buffer...) in strByte

What is the C# way to convert contents of strByte into a string? (C++ would
be the usual.....)
OR, is there a way to even bypass casting step? Strings, strings, string....
Thanks for any help!!!

"John Hoffman" <news.microsoft.com> wrote in message
news:eN**************@TK2MSFTNGP12.phx.gbl...
Reading registry:

...
RegistryKey rksub = rkey.OpenSubKey(s);
String [] valstr = rksub.GetValueNames();
foreach (String vs in valstr)
{
String vstr = rksub.GetValue(vs).ToString();
OR
String vstr = rksub.GetValue(vs);
...

call to GetValue(vs) returns "System.Byte" string if value is reg binary
entry (instead of string or DWORD).
How do you get to actual byte buffer with reg entry value returned as
"System.Byte"?
Thanks

Nov 16 '05 #3
Exception. Didn't work. Thanks
"Robert Misiak" <rm*****@users.cutthispartout.sourceforge.net> wrote in
message news:Bq******************@newsread1.news.pas.earth link.net...
Try casting it:

string vstr = (string)rksub.GetValue(vs);

Robert
"John Hoffman" <news.microsoft.com> wrote in message
news:eN**************@TK2MSFTNGP12.phx.gbl...
Reading registry:

...
RegistryKey rksub = rkey.OpenSubKey(s);
String [] valstr = rksub.GetValueNames();
foreach (String vs in valstr)
{
String vstr = rksub.GetValue(vs).ToString();
OR
String vstr = rksub.GetValue(vs);
...

call to GetValue(vs) returns "System.Byte" string if value is reg binary
entry (instead of string or DWORD).
How do you get to actual byte buffer with reg entry value returned as
"System.Byte"?
Thanks


Nov 16 '05 #4
<"John Hoffman" <news.microsoft.com>> wrote:
Figured out you can cast as follows:

System.Byte[] strByte = (System.Byte[]) rksub.GetValue(vs); // This
returns buffer (say 16 byte buffer...) in strByte

What is the C# way to convert contents of strByte into a string? (C++ would
be the usual.....)
OR, is there a way to even bypass casting step? Strings, strings, string....
Thanks for any help!!!


I have to wonder why you've got a string value in a binary entry to
start with. However, if you have, you just need to do the same as any
other byte[] to string conversion - use Encoding.

See http://www.pobox.com/~skeet/csharp/unicode.html

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #5
I don't have a string. I was just trying how to read in binary data (not
DWORD, not string data) from Registry. C++ is easy. I just noticed that the
debugger in C# tipped it was a System.Byte[]. When I looked to System.Byte
msdn refs, not clear (or maybe I accept I'm brain dead) how to use C# fric'n
syntax to read binary buffer using .NET. Casting? System.Array?
System.Buffer? What do the experts do? That's all. Thanks for effort and
sorry for my lack of patience. It's just that all 'expert' examples at <you
name it web site> show all the DWORD and string examples. Guess they forgot
about binary data in the registry.
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
<"John Hoffman" <news.microsoft.com>> wrote:
Figured out you can cast as follows:

System.Byte[] strByte = (System.Byte[]) rksub.GetValue(vs); // This
returns buffer (say 16 byte buffer...) in strByte

What is the C# way to convert contents of strByte into a string? (C++ would be the usual.....)
OR, is there a way to even bypass casting step? Strings, strings, string.... Thanks for any help!!!


I have to wonder why you've got a string value in a binary entry to
start with. However, if you have, you just need to do the same as any
other byte[] to string conversion - use Encoding.

See http://www.pobox.com/~skeet/csharp/unicode.html

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #6
Sorry, I am brain dead. I was reading in binary data to a System.Byte[]
variable. I was just having problems formatting some of the byte data into a
string to write out. Encoding is the answer. Thanks, and good night!

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
<"John Hoffman" <news.microsoft.com>> wrote:
Figured out you can cast as follows:

System.Byte[] strByte = (System.Byte[]) rksub.GetValue(vs); // This
returns buffer (say 16 byte buffer...) in strByte

What is the C# way to convert contents of strByte into a string? (C++ would be the usual.....)
OR, is there a way to even bypass casting step? Strings, strings, string.... Thanks for any help!!!


I have to wonder why you've got a string value in a binary entry to
start with. However, if you have, you just need to do the same as any
other byte[] to string conversion - use Encoding.

See http://www.pobox.com/~skeet/csharp/unicode.html

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Yeow | last post: by
8 posts views Thread by Saradhi | last post: by
9 posts views Thread by jeff M via .NET 247 | last post: by
7 posts views Thread by John Dann | last post: by
2 posts views Thread by Mad Scientist Jr | last post: by
5 posts views Thread by Scott M. Lyon | last post: by
11 posts views Thread by Freddy Coal | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.