473,749 Members | 2,580 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Reading registry:

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

call to GetValue(vs) returns "System.Byt e" 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.Byt e"?
Thanks
Nov 16 '05 #1
6 16021
Try casting it:

string vstr = (string)rksub.G etValue(vs);

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

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

call to GetValue(vs) returns "System.Byt e" 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.Byt e"?
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******** ******@TK2MSFTN GP12.phx.gbl...
Reading registry:

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

call to GetValue(vs) returns "System.Byt e" 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.Byt e"?
Thanks

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

string vstr = (string)rksub.G etValue(vs);

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

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

call to GetValue(vs) returns "System.Byt e" 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.Byt e"?
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.co m>
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.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
<"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.co m>
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.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
<"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.co m>
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
9530
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 contains the following three floating-point numbers: 1.0 2.0 3.0
8
10677
by: Saradhi | last post by:
Can any one put me a piece of code to write binary data into Registry?
2
3752
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. At least when I execute the following code, I get some significant network traffic. When I check the database with query analyzer, I see 4 Hex Chars in the image colum. Like 0xe0 etc.
9
6776
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 get the correct answer by taking the decimal valueand using that as an index to an array that will map to thecorrect EBCDIC value in hex. By larger values, an example would be "AA" in EBCDIC hex wouldgive me the value of 63 in decimal (ASCII) when...
7
6062
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 populate a series of structures of specified variable composition. I have the structures created OK, but actually reading the files is giving me an error. Can I ask a simple question to start with: I'm trying to read the file using the...
2
1863
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 (an endless loop). i thought that BinaryReader.ReadByte advanced to the next byte? i had it time out after 1000 iterations, and keeps outputting the same byte. any help appreciated, my code is below: Imports System.io
5
8956
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 headers). I used ODBC in my VB.NET program to read that spreadsheet into a dataset, to make it easy to manipulate. The code I use to read it is as the bottom of this posting.
3
3438
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 height;
11
3594
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 Read_bin(ByVal ruta As String) Dim cadena As String = "" Dim dato As Array If File.Exists(ruta) = True Then
0
8996
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8832
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9333
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8256
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6800
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.