473,657 Members | 2,896 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6776

"Chuck B" <ch****@shc1.co mwrote in message
news:eR******** ******@TK2MSFTN GP06.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("adva pi32")]
static extern int RegConnectRegis try(string machine, UIntPtr hKey, out
IntPtr pRemKey);
[DllImport("adva pi32")]
static extern int RegCloseKey(Int Ptr hKey);
[DllImport("adva pi32")]
static extern int RegSaveKey(IntP tr hKey, string fileout, IntPtr
secdesc);

...
// most important keys, other keys -winreg.h
const uint HKEY_CLASSES_RO OT = 0x80000000;
const uint HKEY_CURRENT_US ER = 0x80000001;
const uint HKEY_LOCAL_MACH INE = 0x80000002;

UIntPtr key = new UIntPtr(HKEY_CL ASSES_ROOT);
IntPtr remKey;
int ret = RegConnectRegis try("machineNam e", key, out remKey);
if(ret == 0) {
int r = RegSaveKey(remK ey, "c:\\regRootsav e", IntPtr.Zero);
if(r != 0)
Console.WriteLi ne("Error: {0}", r);
}
if(remKey != IntPtr.Zero)
RegCloseKey(rem Key);
...

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(stri ng keyName, string remoteName)
{
RegistryKey regKey;

try
{
// Open registry on a remote computer.
regKey = RegistryKey.Ope nRemoteBaseKey(
RegistryHive.Lo calMachine, remoteName).Ope nSubKey(keyName );
}
catch(IOExcepti on ex)
{
printOutput(str ing.Format("\n{ 0}: {1}",
ex.GetType().Na me, 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*********@ya hoo.comwrote in message
news:11******** *************@d 34g2000cwd.goog legroups.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(stri ng keyName, string remoteName)
| {
| RegistryKey regKey;
|
| try
| {
| // Open registry on a remote computer.
| regKey = RegistryKey.Ope nRemoteBaseKey(
| RegistryHive.Lo calMachine, remoteName).Ope nSubKey(keyName );
| }
| catch(IOExcepti on ex)
| {
| printOutput(str ing.Format("\n{ 0}: {1}",
| ex.GetType().Na me, 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.bewro te in message
news:um******** *****@TK2MSFTNG P06.phx.gbl...
>
"Chuck B" <ch****@shc1.co mwrote in message
news:eR******** ******@TK2MSFTN GP06.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("adva pi32")]
static extern int RegConnectRegis try(string machine, UIntPtr hKey, out
IntPtr pRemKey);
[DllImport("adva pi32")]
static extern int RegCloseKey(Int Ptr hKey);
[DllImport("adva pi32")]
static extern int RegSaveKey(IntP tr hKey, string fileout, IntPtr
secdesc);

..
// most important keys, other keys -winreg.h
const uint HKEY_CLASSES_RO OT = 0x80000000;
const uint HKEY_CURRENT_US ER = 0x80000001;
const uint HKEY_LOCAL_MACH INE = 0x80000002;

UIntPtr key = new UIntPtr(HKEY_CL ASSES_ROOT);
IntPtr remKey;
int ret = RegConnectRegis try("machineNam e", key, out remKey);
if(ret == 0) {
int r = RegSaveKey(remK ey, "c:\\regRootsav e", IntPtr.Zero);
if(r != 0)
Console.WriteLi ne("Error: {0}", r);
}
if(remKey != IntPtr.Zero)
RegCloseKey(rem Key);
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
3260
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 way to schedule backups so the remote db is backed up to the local machine? Can this be done in Enterprise Manager? Would you recommend any 3rd party software?
4
2297
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 that does not have the actual tables on it. I am using the following DoCmd.TransferDatabase acExport, "Microsoft Access", "Backup.mdb", acTable, "TableName", "TableName" Is there a way to use this and get the tables from a different machine?
3
3050
by: Slimo | last post by:
Hello, I'm searching some example of code (VB) for reading remote registry subkeys and keys. Thanks
3
4608
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 access the local registry bur I'd like to mount several remote registry to check a specific key for a DWORD value. Thanks, Steve
5
7157
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 specify the type of data in the key and get that data output to screen or file. Specifically Reg_Binary or Reg_Multi_Sz Here is just the latest hack that I am working with, most of which is directly from msdn. Any suggestions or modification...
1
1623
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 date. Is there anything that SQL Server saves in the registry or in its home folder that changes frequently? I am hoping that nothing does which means the old backup will be good enough. Although I think the default databases are in the c...
5
6966
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 RegistryKey.OpenRemoteBaseKey(); I tried But everytime I execute it, an UnauthorizedAccessException occurred at the OpenRemoteBaseKey method. Both computer (the one that ran the C# application, and the remote computer) are Windows XP Professional,...
12
5634
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 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?
6
3682
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 the VMware virtual machine... Right up until the application being debugged tries to write to the registry. Then it fails due to lack of security permissions. It writes to the Host PC registry just fine. This is only happening when remote...
0
8302
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
8820
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8718
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...
0
8601
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...
1
6162
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
4150
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...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1937
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.