473,757 Members | 10,708 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
12 5642
On Mon, 02 Jun 2008 13:44:02 -0700, auldh
<au***@discussi ons.microsoft.c omwrote:
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.Wr iteLine(), 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***@discussi ons.microsoft.c omwrote:
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.Wr iteLine(), 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.Unico de" specifiec.

now when i create the output file with StreamWriter and "Encoding.Unico de" 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
4202
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 direct access to the db server. I'd like to give her the facility to export the information in her local Access application to the shared PHP/MySql site. From one command button (or similar) in the Access application.
1
1788
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
4760
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 they simply do a DTS copy. However, we are now moving to a thin client solution where they will be working on a terminal server. They will have access to the development SQL servers and SQL tools such as EM and QA. However, they will not have...
2
2266
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 modify the file. In other words I'm storing the paths (for centralizing purposes) as custom <appSettings> in the web.config. expample (for local testing): <add key="imagePath" value="http://localhost/app_folder/10_media/images/" />
1
1897
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 at all. Now, I'm trying to deploy the app I done to a windows 2003 server, with IIS 6.0 and in wich I installed the Visual Studio 2003 server components (for web development). It has ASP.Net 1.1 too.
3
4597
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 its value. In .NET 1.1 this worked fine, however under .NET 2.0 it fails when I am not an administrator on the remote server. To provide a lean demonstration of the issue, I created the following class: ============================
3
8322
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 read, 1 works, and the other gives me the "Requested registry access is not allowed." i've narrowed it down to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office It doesnt let me access that path, but the permissions are the same.
8
6673
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
1816
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. Everything works fine. The remote amchine goes to clear the table and then insert all 10,000 records, into the table the following happens. 1) the local machines queries do not compilete until the remote machine is done.
0
9489
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
9298
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,...
0
9906
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9885
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
9737
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8737
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...
0
6562
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
5172
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3399
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.