-
Notifications
You must be signed in to change notification settings - Fork 12
/
Reg.cs
32 lines (29 loc) · 1.11 KB
/
Reg.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System;
using static RegSave.Interop;
namespace RegSave
{
internal class Reg
{
public static UIntPtr HKEY_LOCAL_MACHINE = new UIntPtr(0x80000002u);
public static int KEY_READ = 0x20019;
public static int KEY_ALL_ACCESS = 0xF003F;
public static int REG_OPTION_OPEN_LINK = 0x0008;
public static int REG_OPTION_BACKUP_RESTORE = 0x0004;
public static int KEY_QUERY_VALUE = 0x1;
public static void ExportRegKey(string key, string outFile)
{
var hKey = UIntPtr.Zero;
try
{
RegOpenKeyEx(HKEY_LOCAL_MACHINE, key, REG_OPTION_BACKUP_RESTORE | REG_OPTION_OPEN_LINK, KEY_ALL_ACCESS, out hKey); //https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regcreatekeyexa
RegSaveKey(hKey, outFile, IntPtr.Zero);
RegCloseKey(hKey);
Console.WriteLine("Exported HKLM\\{0} at {1}", key, outFile);
}
catch (Exception e)
{
throw e;
}
}
}
}