private static RegistryKey OpenRemoteBaseKeyCore(RegistryHive hKey, string machineName, RegistryView view)
{
int index = (int)hKey & 0x0FFFFFFF;
if (index < 0 || index >= s_hkeyNames.Length || ((int)hKey & 0xFFFFFFF0) != 0x80000000)
{
throw new ArgumentException(SR.Arg_RegKeyOutOfRange);
}
// connect to the specified remote registry
SafeRegistryHandle foreignHKey = null;
int ret = Interop.Advapi32.RegConnectRegistry(machineName, new SafeRegistryHandle(new IntPtr((int)hKey), false), out foreignHKey);
if (ret == Interop.Errors.ERROR_DLL_INIT_FAILED)
{
// return value indicates an error occurred
throw new ArgumentException(SR.Arg_DllInitFailure);
}
if (ret != 0)
{
Win32ErrorStatic(ret, null);
}
if (foreignHKey.IsInvalid)
{
// return value indicates an error occurred
throw new ArgumentException(SR.Format(SR.Arg_RegKeyNoRemoteConnect, machineName));
}
RegistryKey key = new RegistryKey(foreignHKey, true, false, true, ((IntPtr)hKey) == HKEY_PERFORMANCE_DATA, view);
key._keyName = s_hkeyNames[index];
return key;
}