473,381 Members | 1,446 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,381 software developers and data experts.

local and remote machine registry export

i current have a way to read both local and remote machines registry keys and
create a textual view (.txt output).

i now looking for ways to do export of local and remote mahcine registry
keys into ".reg" file format via C#.

is this do able?
what do i need to research to do this?

or is where i need to windows WinApi?
Jun 27 '08 #1
12 5604
On Fri, 30 May 2008 13:15:01 -0700, auldh
<au***@discussions.microsoft.comwrote:
i current have a way to read both local and remote machines registry
keys and
create a textual view (.txt output).
In C#?
i now looking for ways to do export of local and remote mahcine registry
keys into ".reg" file format via C#.
If you already have code that produces text output of the registry, you're
most of the way there. The .reg file format is extremely simple. You
just need to specify specific key paths in square braces, with individual
values following. Here's a reasonable complete discussion:
http://support.microsoft.com/kb/310516

Other than following that specific format, I wouldn't expect much changes
from the code you already have.
is this do able?
what do i need to research to do this?
If you don't already have text output of the registry using .NET, you may
want to look here:
http://msdn.microsoft.com/en-us/libr....registry.aspx

Pete
Jun 27 '08 #2
Peter,
thanks for your response.
yes i have C# code to create a textual file of the registry key hive i want.
but i read the 2 kbs and i don't see how to use C# to create the ".reg" file
export.
they talk about using regedit. i can not export remote machine registry keys
this way.

i need to create an export file in ".reg" format for both local and remote
servers (machines).
"Peter Duniho" wrote:
On Fri, 30 May 2008 13:15:01 -0700, auldh
<au***@discussions.microsoft.comwrote:
i current have a way to read both local and remote machines registry
keys and
create a textual view (.txt output).

In C#?
i now looking for ways to do export of local and remote mahcine registry
keys into ".reg" file format via C#.

If you already have code that produces text output of the registry, you're
most of the way there. The .reg file format is extremely simple. You
just need to specify specific key paths in square braces, with individual
values following. Here's a reasonable complete discussion:
http://support.microsoft.com/kb/310516

Other than following that specific format, I wouldn't expect much changes
from the code you already have.
is this do able?
what do i need to research to do this?

If you don't already have text output of the registry using .NET, you may
want to look here:
http://msdn.microsoft.com/en-us/libr....registry.aspx

Pete
Jun 27 '08 #3
On Fri, 30 May 2008 15:31:00 -0700, auldh
<au***@discussions.microsoft.comwrote:
thanks for your response.
yes i have C# code to create a textual file of the registry key hive i
want.
but i read the 2 kbs and i don't see how to use C# to create the ".reg"
file
export.
they talk about using regedit. i can not export remote machine registry
keys
this way.

i need to create an export file in ".reg" format for both local and
remote
servers (machines).
The first article I provided documents the .reg file format. I'm not
aware of any support in .NET to write the format automatically (though it
might yet exist). But the format is so simple that if you already have
code to emit the registry information in _any_ format, it shouldn't take
you more than 15 minutes or so to change the code to comply with the
actual .reg file format. 30 minutes at the outside.

Heck...from scratch, the whole thing should a few hours work at the most,
and quicker for someone already very familiar with .NET.

Pete
Jun 27 '08 #4
will the file i create be able to be used by regedit to import on a machine?
i light is still not coming on.
"Peter Duniho" wrote:
On Fri, 30 May 2008 15:31:00 -0700, auldh
<au***@discussions.microsoft.comwrote:
thanks for your response.
yes i have C# code to create a textual file of the registry key hive i
want.
but i read the 2 kbs and i don't see how to use C# to create the ".reg"
file
export.
they talk about using regedit. i can not export remote machine registry
keys
this way.

i need to create an export file in ".reg" format for both local and
remote
servers (machines).

The first article I provided documents the .reg file format. I'm not
aware of any support in .NET to write the format automatically (though it
might yet exist). But the format is so simple that if you already have
code to emit the registry information in _any_ format, it shouldn't take
you more than 15 minutes or so to change the code to comply with the
actual .reg file format. 30 minutes at the outside.

Heck...from scratch, the whole thing should a few hours work at the most,
and quicker for someone already very familiar with .NET.

Pete
Jun 27 '08 #5
i think i can build the string and dword registry key to mimic the regedit
export file. but i'm seeing a problem constructing the "REG_MULTI_SZ" output
so that it mimics the regedit structure.

my code does a good job of getting the string but i'm not understanding how
to keep the value as binary.

"auldh" wrote:
will the file i create be able to be used by regedit to import on a machine?
i light is still not coming on.
"Peter Duniho" wrote:
On Fri, 30 May 2008 15:31:00 -0700, auldh
<au***@discussions.microsoft.comwrote:
thanks for your response.
yes i have C# code to create a textual file of the registry key hive i
want.
but i read the 2 kbs and i don't see how to use C# to create the ".reg"
file
export.
they talk about using regedit. i can not export remote machine registry
keys
this way.
>
i need to create an export file in ".reg" format for both local and
remote
servers (machines).
The first article I provided documents the .reg file format. I'm not
aware of any support in .NET to write the format automatically (though it
might yet exist). But the format is so simple that if you already have
code to emit the registry information in _any_ format, it shouldn't take
you more than 15 minutes or so to change the code to comply with the
actual .reg file format. 30 minutes at the outside.

Heck...from scratch, the whole thing should a few hours work at the most,
and quicker for someone already very familiar with .NET.

Pete
Jun 27 '08 #6
On Fri, 30 May 2008 21:21:00 -0700, auldh
<au***@discussions.microsoft.comwrote:
will the file i create be able to be used by regedit to import on a
machine?
i light is still not coming on.
Yes. The .reg file format is just a text file with a particular format
for the text contained within.

Again, I direct you to the Microsoft KB article I mentioned earlier, that
describes the format.

Pete
Jun 27 '08 #7
Peter you are smarter person than i.
i understand what i read. but using the C# registry class i don't see how to
get the "REG_MULTI_SZ".

i can get a string output but i can not build the output as created by
regedit:
"WrapperComponentList"=hex(7):4d,00,53,00,44,00,45 ,00,00,00,53,00,45,00,52,00,\
56,00,45,00,52,00,5f,00,4d,00,52,00,53,00,5f,00,4c ,00,4f,00,43,00,41,00,4c,\
00,00,00,4c,00,41,00,4e,00,47,00,55,00,41,00,47,00 ,45,00,5f,00,45,00,4e,00,\
47,00,4c,00,49,00,53,00,48,00,55,00,53,00,00,00,43 ,00,4f,00,4d,00,4d,00,55,\
00,4e,00,49,00,43,00,41,00,54,00,49,00,4f,00,4e,00 ,53,00,5f,00,43,00,4c,00,\
49,00,45,00,4e,00,54,00,00,00,41,00,50,00,50,00,47 ,00,45,00,4e,00,00,00,4d,\
00,4d,00,43,00,5f,00,53,00,4e,00,41,00,50,00,49,00 ,4e,00,00,00,54,00,54,00,\
53,00,5f,00,45,00,4e,00,47,00,49,00,4e,00,45,00,00 ,00,00,00

i need to be able to create registry export file for both local and remote
machine/server that another group can restore via regedit to work in a lab.
the output file needs to mimic the registry export.

however creating a program to run regedit command line will only work on the
local machine. my task is to export the registry for both the master and
slave server so i can provide the data to someone else.

i can get to the string, dword but the muti_sz string is where i'm failing.
they build a string output.

"Peter Duniho" wrote:
On Fri, 30 May 2008 21:21:00 -0700, auldh
<au***@discussions.microsoft.comwrote:
will the file i create be able to be used by regedit to import on a
machine?
i light is still not coming on.

Yes. The .reg file format is just a text file with a particular format
for the text contained within.

Again, I direct you to the Microsoft KB article I mentioned earlier, that
describes the format.

Pete
Jun 27 '08 #8
On Mon, 02 Jun 2008 12:48:01 -0700, auldh
<au***@discussions.microsoft.comwrote:
Peter you are smarter person than i.
Maybe. Maybe not. Too early to tell. :)
i understand what i read. but using the C# registry class i don't see
how to
get the "REG_MULTI_SZ".

i can get a string output but i can not build the output as created by
regedit:
"WrapperComponentList"=hex(7):4d,00,53,00,44,00,45 ,00,00,00,53,00,45,00,52,00,\
56,00,45,00,52,00,5f,00,4d,00,52,00,53,00,5f,00,4c ,00,4f,00,43,00,41,00,4c,\
00,00,00,4c,00,41,00,4e,00,47,00,55,00,41,00,47,00 ,45,00,5f,00,45,00,4e,00,\
47,00,4c,00,49,00,53,00,48,00,55,00,53,00,00,00,43 ,00,4f,00,4d,00,4d,00,55,\
00,4e,00,49,00,43,00,41,00,54,00,49,00,4f,00,4e,00 ,53,00,5f,00,43,00,4c,00,\
49,00,45,00,4e,00,54,00,00,00,41,00,50,00,50,00,47 ,00,45,00,4e,00,00,00,4d,\
00,4d,00,43,00,5f,00,53,00,4e,00,41,00,50,00,49,00 ,4e,00,00,00,54,00,54,00,\
53,00,5f,00,45,00,4e,00,47,00,49,00,4e,00,45,00,00 ,00,00,00
Well, what exactly is it that you're having difficulty with?

I mean, I can see a number of places that might trip a person up, but if
you can already output the registry as a .txt file (as you wrote in your
original post), how does that output differ from the above? What do you
need help with specifically?

Pete
Jun 27 '08 #9
the output i can create for a "multi_sz" is something like this:
Number of records in WrapperComponentList = 4
WrapperComponentList = (REG_MULTI_SZ) DRIVER_US
WrapperComponentList = (REG_MULTI_SZ) MSDE
WrapperComponentList = (REG_MULTI_SZ) SERVER_MRS_LOCAL
WrapperComponentList = (REG_MULTI_SZ) LANGUAGE_ENGLISHUS

my code:
else if (t == System.Type.GetType("System.String[]"))
{
String[] sval = (String[])regvalue;
sw.WriteLine(String.Format("Number of records in {0} =
{1}", valueName, sval.Length.ToString()));
for (int i = 0; i < sval.Length; i++)
{
sw.WriteLine("\t\t{0} = (REG_MULTI_SZ) {1}",
valueName, sval[i]);
}
}
else
{
sw.WriteLine(String.Format("\t\tValue Name: {0}; Data:
{1} ; Type: {2}", valueName, regvalue.ToString(), t));
}

creates the output to be strings as seen above.
and according to "regedit" it can not import the structure i have.

the output file needs to have the following format:
"WrapperComponentList"=hex(7):44,00,52,00,49,00,56 ,00,45,00,52,00,5f,00,55,00,\
53,00,00,00,4d,00,53,00,44,00,45,00,00,00,53,00,45 ,00,52,00,56,00,45,00,52,\
00,5f,00,4d,00,52,00,53,00,5f,00,4c,00,4f,00,43,00 ,41,00,4c,00,00,00,4c,00,\
41,00,4e,00,47,00,55,00,41,00,47,00,45,00,5f,00,45 ,00,4e,00,47,00,4c,00,49,\
00,53,00,48,00,55,00,53,00,00,00,00,00

i must be over thinking this cause i'm not having success stepping through
the registry value to create the ascii string above.

"Peter Duniho" wrote:
On Mon, 02 Jun 2008 12:48:01 -0700, auldh
<au***@discussions.microsoft.comwrote:
Peter you are smarter person than i.

Maybe. Maybe not. Too early to tell. :)
i understand what i read. but using the C# registry class i don't see
how to
get the "REG_MULTI_SZ".

i can get a string output but i can not build the output as created by
regedit:
"WrapperComponentList"=hex(7):4d,00,53,00,44,00,45 ,00,00,00,53,00,45,00,52,00,\
56,00,45,00,52,00,5f,00,4d,00,52,00,53,00,5f,00,4c ,00,4f,00,43,00,41,00,4c,\
00,00,00,4c,00,41,00,4e,00,47,00,55,00,41,00,47,00 ,45,00,5f,00,45,00,4e,00,\
47,00,4c,00,49,00,53,00,48,00,55,00,53,00,00,00,43 ,00,4f,00,4d,00,4d,00,55,\
00,4e,00,49,00,43,00,41,00,54,00,49,00,4f,00,4e,00 ,53,00,5f,00,43,00,4c,00,\
49,00,45,00,4e,00,54,00,00,00,41,00,50,00,50,00,47 ,00,45,00,4e,00,00,00,4d,\
00,4d,00,43,00,5f,00,53,00,4e,00,41,00,50,00,49,00 ,4e,00,00,00,54,00,54,00,\
53,00,5f,00,45,00,4e,00,47,00,49,00,4e,00,45,00,00 ,00,00,00

Well, what exactly is it that you're having difficulty with?

I mean, I can see a number of places that might trip a person up, but if
you can already output the registry as a .txt file (as you wrote in your
original post), how does that output differ from the above? What do you
need help with specifically?

Pete
Jun 27 '08 #10
On Mon, 02 Jun 2008 13:44:02 -0700, auldh
<au***@discussions.microsoft.comwrote:
the output i can create for a "multi_sz" is something like this: [snip]
Now we're getting somewhere! That example was precisely the sort of
information needed to elaborate on your question.
[...]
creates the output to be strings as seen above.
and according to "regedit" it can not import the structure i have.
Yes, that's true. As the docs say, and as you're aware, there's a
specific format required and that format is different from the one you're
using.

You need to do a couple of things. Ironically, using the managed
RegistryKey class makes things harder in one respect: the data returned is
not actually exactly how the data appears in the registry, so you need to
convert _back_ to the correct format so that you can then write it to the
text file. Were you using the unmanaged API (e.g. RegQueryValueEx), you'd
just get the appropriate bytes directly (assuming you defined "UNICODE",
which IMHO any modern application should :) ).

Anyway, so the first thing you need to do is generate the necessary byte
array. You can use the Unicode instance of the Encoding class to convert
each string to a string of bytes. The REG_MULTI_SZ format is, as you can
probably tell by looking at the example you posted, a single byte array
containing null-terminated Unicode strings, with one more null-terminator
after the last null-terminated string (basically, it ends in a zero-length
string :) ).

So, you need to enumerate all your strings, convert them to Unicode bytes,
and fill a single byte array with the result. There are lots of ways to
do this, but the simplest is probably just to create a MemoryStream, write
the individual string byte arrays you get (including null-termination) to
the MemoryStream, and then get the bytes out from the MemoryStream at the
end. Don't forget that last zero-length string at the end (the extra
null-terminator).

Once you have this array of bytes, you need to write to the text file,
using hexadecimal formatting. The "X" formatting code can be used for
this, along with normal text output (e.g. StreamWriter.WriteLine(), which
you already seem to be using). Make sure you specify a 2-character field
width for each byte, and of course separate them with commas, exactly as
in your example. I don't actually know if the line-continuations are
required or if you can simply emit one long line. But you might want to
include the line-continuations even if they're not mandatory, since it
makes the file easier to read (granted, not many people are going to be
reading the byte values directly, but still... :) ).

Hope that helps. :)

Pete
Jun 27 '08 #11
Peter,
once again thanks.
i will do the research and work on this. this is great tips.

"Peter Duniho" wrote:
On Mon, 02 Jun 2008 13:44:02 -0700, auldh
<au***@discussions.microsoft.comwrote:
the output i can create for a "multi_sz" is something like this: [snip]

Now we're getting somewhere! That example was precisely the sort of
information needed to elaborate on your question.
[...]
creates the output to be strings as seen above.
and according to "regedit" it can not import the structure i have.

Yes, that's true. As the docs say, and as you're aware, there's a
specific format required and that format is different from the one you're
using.

You need to do a couple of things. Ironically, using the managed
RegistryKey class makes things harder in one respect: the data returned is
not actually exactly how the data appears in the registry, so you need to
convert _back_ to the correct format so that you can then write it to the
text file. Were you using the unmanaged API (e.g. RegQueryValueEx), you'd
just get the appropriate bytes directly (assuming you defined "UNICODE",
which IMHO any modern application should :) ).

Anyway, so the first thing you need to do is generate the necessary byte
array. You can use the Unicode instance of the Encoding class to convert
each string to a string of bytes. The REG_MULTI_SZ format is, as you can
probably tell by looking at the example you posted, a single byte array
containing null-terminated Unicode strings, with one more null-terminator
after the last null-terminated string (basically, it ends in a zero-length
string :) ).

So, you need to enumerate all your strings, convert them to Unicode bytes,
and fill a single byte array with the result. There are lots of ways to
do this, but the simplest is probably just to create a MemoryStream, write
the individual string byte arrays you get (including null-termination) to
the MemoryStream, and then get the bytes out from the MemoryStream at the
end. Don't forget that last zero-length string at the end (the extra
null-terminator).

Once you have this array of bytes, you need to write to the text file,
using hexadecimal formatting. The "X" formatting code can be used for
this, along with normal text output (e.g. StreamWriter.WriteLine(), which
you already seem to be using). Make sure you specify a 2-character field
width for each byte, and of course separate them with commas, exactly as
in your example. I don't actually know if the line-continuations are
required or if you can simply emit one long line. But you might want to
include the line-continuations even if they're not mandatory, since it
makes the file easier to read (granted, not many people are going to be
reading the byte values directly, but still... :) ).

Hope that helps. :)

Pete
Jun 27 '08 #12
just to finish this thread i thought i add what i have found.

when i created my registry export file i used StreamWriter without any
specific codepage encoding.

not mention in the MSDN links is that the output "reg" file should be
"Encoding.Unicode" specifiec.

now when i create the output file with StreamWriter and "Encoding.Unicode" i
can get a perfect replication of the regedit export.

thanks for all your help.
Jun 27 '08 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Mike MacSween | last post by:
My client has an MS Access database application on her local machine. I have full access to that in terms of changing the design. I've got a simple PHP/MySql application on shared hosting, so no...
1
by: Cherry | last post by:
Hi, can I access the registry of a remote machine using VB.NET? While connecting to the remote machine I would be using the admin login of that machine. Thanks.
4
by: oceanhai | last post by:
We currently have a PPTP connection set up for our developers to access our development SQL server through a VPN tunnel. When they need to copy tables up to the dev SQL from their local machine...
2
by: enrique | last post by:
Hello everyone, I'm looking for a "directory path" solution that will allows me to test my app locally and then test on remote web server without having to update my web.config file each time I...
1
by: lauralucas | last post by:
Hello I'm using ASP.NET 1.1, Visual Studio 2003, IIS 5.1 and windows XP as development machine. I can work in this machine locally and create web apps that I can access via localhost. No problem...
3
by: Geoff McElhanon | last post by:
I have been struggling with a security issue that occurs under .NET 2.0, but does not occur under .NET 1.1. Essentially I am trying to open up a performance counter on a remote server and monitor...
3
by: JB | last post by:
I am trying to access a registry key on computer like so: key = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, computerName).OpenSubKey(Subkey); There are two keys I am trying to...
8
by: Hayato Iriumi | last post by:
Hello, folks. I have a need to get the value of %windir% on a remote machine. Is it possible to get this value using C#?
4
by: quincy451 | last post by:
I am running MS SQL 2000 server. The table involved is only about 10,000 records. But this is the behavior I am seeing. The local machine is querying the table looking for a particular record....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.