C
Chuck B
I am modifying remote registries for about 150 computers. Is there any easy
way in C# to do a remote registry backup?
way in C# to do a remote registry backup?
Chuck said:I am modifying remote registries for about 150 computers. Is there any easy
way in C# to do a remote registry backup?
Willy Denoyette said:|
| 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 checkpointsso 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);