How to import ZwDeleteKey in C#: "External component has thrown an exception"

I am trying to use ZwDeleteKey to delete a registry symbolic link. I imported it like that: [DllImport("NtosKrnl.exe", CharSet = CharSet.Ansi, EntryPoint = "ZwDeleteKey", SetLastError = true)] private static extern int ZwDeleteKey(SafeRegistryHandle hKey); But after I call it, I receive an exception: "External component has thrown an exception" My full code: [DllImport("NtosKrnl.exe", CharSet = CharSet.Ansi,… Read More How to import ZwDeleteKey in C#: "External component has thrown an exception"

How to initialize RegistryKey variable

I have a function (OpenSubKeySymLink) that receives this kind of variable: this RegistryKey key. I don’t know how to initialize it and pass it to the function. public static RegistryKey OpenSubKeySymLink(this RegistryKey key, string name, RegistryRights rights = RegistryRights.ReadKey, RegistryView view = 0) { var error = RegOpenKeyExW(key.Handle, name, REG_OPTION_OPEN_LINK, ((int)rights) | ((int)view), out var… Read More How to initialize RegistryKey variable