472,808 Members | 2,078 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,808 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 15936
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.