[DllImport("coredll.dll")]
public static extern int RegCreateKeyEx(
UIntPtr hKey, string lpSubKey, uint dwReserved, string lpClass,
uint dwOptions, int samDesired, IntPtr lpSecurityAttributes,
out IntPtr phkResult, out RegistryDispositionValue lpdwDisposition);
enum RegistryDispositionValue : uint
{
REG_CREATED_NEW_KEY = 0x00000001,
REG_OPENED_EXISTING_KEY = 0x00000002
}
The .NET Compact Framework does not contain a HandleRef type, so it may be necessary to call GC.KeepAlive after calling this function if the calling class wraps the hKey parameter as an unmanaged resource.
C#:
public UIntPtr HKEY_CLASSES_ROOT = (UIntPtr)0x80000000;
public const int REG_OPTION_NON_VOLATILE = 0;
:::
int iResult;
string strRegKeyPath;
int iDisposition;
iResult = RegCreateKeyEx(HKEY_CLASSES_ROOT, strRegKeyPath, 0,
null, REG_OPTION_NON_VOLATILE, 0, IntPtr.Zero, out ipKey,
out iDisposition);
CF V2.0
Microsoft.Win32.Registry.LocalMachine.CreateSubKey(SubKey as string)