473,320 Members | 2,098 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 15985
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Yeow | last post by:
hello, i was trying to use the fread function on SunOS and ran into some trouble. i made a simple test as follows: i'm trying to read in a binary file (generated from a fortran code) that...
8
by: Saradhi | last post by:
Can any one put me a piece of code to write binary data into Registry?
2
by: Chucker | last post by:
Hi Community, I think I can store Binary Data in SQL Server but when I try to retrieve it, I always only get one byte. I think I stored my Binary Data in SQL Server in a Colum of Type Image....
9
by: jeff M via .NET 247 | last post by:
I'm still having problems reading EBCDIC files. Currently itlooks like the lower range (0 to 127) is working. I have triedthe following code pages 20284, 20924, 1140, 37, 500 and 20127.By working I...
7
by: John Dann | last post by:
I'm trying to read some binary data from a file created by another program. I know the binary file format but can't change or control the format. The binary data is organised such that it should...
2
by: Mad Scientist Jr | last post by:
i'm trying to read a file byte by byte (and later alter the data and write it to a 2nd file byte by byte) and running into a problem where it seems to keep reading the same byte over and over again...
5
by: Scott M. Lyon | last post by:
I've just discovered a bug in some code I wrote a little while ago, and I need you guys' help to fix it. My program imports data from a standard Excel Spreadsheet (just with specific column...
3
by: Zeke Zinzul | last post by:
Hi Guys & Geeks, What's the most elegant way of dealing with binary data and structures? Say I have this (which I actually do, a woo-hoo): struct Struct_IconHeader { byte width; byte...
11
by: Freddy Coal | last post by:
Hi, I'm trying to read a binary file of 2411 Bytes, I would like load all the file in a String. I make this function for make that: '-------------------------- Public Shared Function...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.