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

Remote Registry Backup


I am modifying remote registries for about 150 computers. Is there any easy
way in C# to do a remote registry backup?
Sep 22 '06 #1
4 6734

"Chuck B" <ch****@shc1.comwrote in message
news:eR**************@TK2MSFTNGP06.phx.gbl...
|
| I am modifying remote registries for about 150 computers. Is there any
easy
| way in C# to do a remote registry backup?
|
|

You'll have to PInvoke the advapi32 API's for this.
Following a code snip to get you started, note that the road to a remote
registry is paved with security checkpoints :-) so I suggest you carefully
read the MSDN docs before you dive into this.

...
[DllImport("advapi32")]
static extern int RegConnectRegistry(string machine, UIntPtr hKey, out
IntPtr pRemKey);
[DllImport("advapi32")]
static extern int RegCloseKey(IntPtr hKey);
[DllImport("advapi32")]
static extern int RegSaveKey(IntPtr hKey, string fileout, IntPtr
secdesc);

...
// most important keys, other keys -winreg.h
const uint HKEY_CLASSES_ROOT = 0x80000000;
const uint HKEY_CURRENT_USER = 0x80000001;
const uint HKEY_LOCAL_MACHINE = 0x80000002;

UIntPtr key = new UIntPtr(HKEY_CLASSES_ROOT);
IntPtr remKey;
int ret = RegConnectRegistry("machineName", key, out remKey);
if(ret == 0) {
int r = RegSaveKey(remKey, "c:\\regRootsave", IntPtr.Zero);
if(r != 0)
Console.WriteLine("Error: {0}", r);
}
if(remKey != IntPtr.Zero)
RegCloseKey(remKey);
...

Willy.

Sep 22 '06 #2
Chuck B wrote:
I am modifying remote registries for about 150 computers. Is there any easy
way in C# to do a remote registry backup?
How about something like this:

using Microsoft.Win32;

private void openSubkey(string keyName, string remoteName)
{
RegistryKey regKey;

try
{
// Open registry on a remote computer.
regKey = RegistryKey.OpenRemoteBaseKey(
RegistryHive.LocalMachine, remoteName).OpenSubKey(keyName);
}
catch(IOException ex)
{
printOutput(string.Format("\n{0}: {1}",
ex.GetType().Name, ex.Message));
return;
}

if (regKey != null)
{
...

// Close the registry key.
regKey.Close();
}
}

Of course you'll have to be logged-in as an administrator for those
computers.

Eric

Sep 22 '06 #3
I don't think this answers the OP's question!

..... C# to do a remote registry backup?
Willy.

"Eric" <en*********@yahoo.comwrote in message
news:11*********************@d34g2000cwd.googlegro ups.com...
| Chuck B wrote:
|
| I am modifying remote registries for about 150 computers. Is there any
easy
| way in C# to do a remote registry backup?
|
| How about something like this:
|
| using Microsoft.Win32;
|
| private void openSubkey(string keyName, string remoteName)
| {
| RegistryKey regKey;
|
| try
| {
| // Open registry on a remote computer.
| regKey = RegistryKey.OpenRemoteBaseKey(
| RegistryHive.LocalMachine, remoteName).OpenSubKey(keyName);
| }
| catch(IOException ex)
| {
| printOutput(string.Format("\n{0}: {1}",
| ex.GetType().Name, ex.Message));
| return;
| }
|
| if (regKey != null)
| {
| ...
|
| // Close the registry key.
| regKey.Close();
| }
| }
|
| Of course you'll have to be logged-in as an administrator for those
| computers.
|
| Eric
|
Sep 22 '06 #4

"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message
news:um*************@TK2MSFTNGP06.phx.gbl...
>
"Chuck B" <ch****@shc1.comwrote in message
news:eR**************@TK2MSFTNGP06.phx.gbl...
|
| I am modifying remote registries for about 150 computers. Is there any
easy
| way in C# to do a remote registry backup?
|
|

You'll have to PInvoke the advapi32 API's for this.
Following a code snip to get you started, note that the road to a remote
registry is paved with security checkpoints :-) so I suggest you carefully
read the MSDN docs before you dive into this.

..
[DllImport("advapi32")]
static extern int RegConnectRegistry(string machine, UIntPtr hKey, out
IntPtr pRemKey);
[DllImport("advapi32")]
static extern int RegCloseKey(IntPtr hKey);
[DllImport("advapi32")]
static extern int RegSaveKey(IntPtr hKey, string fileout, IntPtr
secdesc);

..
// most important keys, other keys -winreg.h
const uint HKEY_CLASSES_ROOT = 0x80000000;
const uint HKEY_CURRENT_USER = 0x80000001;
const uint HKEY_LOCAL_MACHINE = 0x80000002;

UIntPtr key = new UIntPtr(HKEY_CLASSES_ROOT);
IntPtr remKey;
int ret = RegConnectRegistry("machineName", key, out remKey);
if(ret == 0) {
int r = RegSaveKey(remKey, "c:\\regRootsave", IntPtr.Zero);
if(r != 0)
Console.WriteLine("Error: {0}", r);
}
if(remKey != IntPtr.Zero)
RegCloseKey(remKey);
Thanks again Willy. Without your help I might be doing this via sneakernet.
Not a fun thought with some 150 computers... :p
Sep 25 '06 #5

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

Similar topics

1
by: mbailey | last post by:
Hello- I have a Sql Server 2000 database offsite that I would like to back up to a local machine. I am using Enterprise Manager on a local machine to administer the remote db. Whats the best...
4
by: ShyGuy | last post by:
I have a routine that creates a new database and then copies a couple of tables to the new database as backups. It works fine but I want to split the database and run this routine from a machine...
3
by: Slimo | last post by:
Hello, I'm searching some example of code (VB) for reading remote registry subkeys and keys. Thanks
3
by: Steve Montgomery | last post by:
Does anyone have a sample block of code they can share for checking a DWORD value on a remote network machine's registry? For example, to validate a patch deployment. MSDN has a great sample for...
5
by: Matt Brandes | last post by:
I am looking for a solution that would allow me to recursively backup a given registry key that I could then use to import into another machine. The problem that I keep having is the inability to...
1
by: John Dalberg | last post by:
I have my SQL Server installation on drive c: and the databases on another drive. My c drive got corrupted and I am planning to restore it from an old backup. This means drive c will not be up to...
5
by: Sin Jeong-hun | last post by:
I need to read some registry keys of a remote computer. The key will be any key users provide. (For example : HKEY_CURRENT_USER\SOFTWARE \MyGame) I found that there was a handy method called...
12
by: =?Utf-8?B?YXVsZGg=?= | last post by:
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...
6
tlhintoq
by: tlhintoq | last post by:
I pride myself on being able to Google just about anything but... I have fought, tried, searched and fought some more on this one. I am using VMware, and am able to debug from Visual Studio to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.