예제 #1
0
        public RegistryHandle OpenSubKey(string subkey)
        {
            RegistryHandle hkResult = null;

            if (((SafeNativeMethods.RegOpenKeyEx(this, subkey, 0, 0x20019, out hkResult) == 0) && (hkResult != null)) && !hkResult.IsInvalid)
            {
                return(hkResult);
            }
            Utility.CloseInvalidOutSafeHandle(hkResult);
            return(null);
        }
        public RegistryHandle OpenSubKey(string subkey)
        {
            RegistryHandle regHandle = null;
            int            status    = SafeNativeMethods.RegOpenKeyEx(this, subkey, 0, SafeNativeMethods.KEY_READ, out regHandle);

            if (status != SafeNativeMethods.ERROR_SUCCESS || regHandle == null || regHandle.IsInvalid)
            {
                Utility.CloseInvalidOutSafeHandle(regHandle);
                return(null);
            }
            return(regHandle);
        }
예제 #3
0
        internal static RegistryHandle GetNativeHKLMSubkey(string subKey, bool writeable)
        {
            RegistryHandle hkResult   = null;
            int            samDesired = 0x20119;

            if (writeable)
            {
                samDesired |= 0x20006;
            }
            if (((SafeNativeMethods.RegOpenKeyEx(HKEY_LOCAL_MACHINE, subKey, 0, samDesired, out hkResult) == 0) && (hkResult != null)) && !hkResult.IsInvalid)
            {
                return(hkResult);
            }
            Utility.CloseInvalidOutSafeHandle(hkResult);
            return(null);
        }
예제 #4
0
        private static RegistryHandle Get64bitHKLMSubkey(string key)
        {
            RegistryHandle hkResult = null;
            int            error    = SafeNativeMethods.RegOpenKeyEx(HKEY_LOCAL_MACHINE, key, 0, 0x20119, out hkResult);

            if (error != 0)
            {
                Utility.CloseInvalidOutSafeHandle(hkResult);
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new Win32Exception(error));
            }
            if ((hkResult != null) && !hkResult.IsInvalid)
            {
                return(hkResult);
            }
            Utility.CloseInvalidOutSafeHandle(hkResult);
            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new Win32Exception(6));
        }
예제 #5
0
        private static RegistryHandle Get32bitHKCR()
        {
            RegistryHandle hkResult = null;
            int            error    = SafeNativeMethods.RegOpenKeyEx(HKEY_LOCAL_MACHINE, @"Software\Classes", 0, 0x20219, out hkResult);

            if (error != 0)
            {
                Utility.CloseInvalidOutSafeHandle(hkResult);
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new Win32Exception(error));
            }
            if ((hkResult != null) && !hkResult.IsInvalid)
            {
                return(hkResult);
            }
            Utility.CloseInvalidOutSafeHandle(hkResult);
            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new Win32Exception(6));
        }
        static RegistryHandle Get32bitHKLMSubkey(string key)
        {
            RegistryHandle regHandle = null;
            int            status    = SafeNativeMethods.RegOpenKeyEx(HKEY_LOCAL_MACHINE, key, 0, SafeNativeMethods.KEY_READ | SafeNativeMethods.KEY_WOW64_32KEY, out regHandle);

            if (status != SafeNativeMethods.ERROR_SUCCESS)
            {
                Utility.CloseInvalidOutSafeHandle(regHandle);
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new Win32Exception(status));
            }
            if (null == regHandle || regHandle.IsInvalid)
            {
                Fx.Assert("Get32bitHKLMSubkey: RegOpenKeyEx returned null but with an invalid handle.");
                Utility.CloseInvalidOutSafeHandle(regHandle);
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new Win32Exception(SafeNativeMethods.ERROR_INVALID_HANDLE));
            }
            return(regHandle);
        }
        internal static RegistryHandle GetNativeHKLMSubkey(string subKey, bool writeable)
        {
            RegistryHandle regHandle  = null;
            int            samDesired = SafeNativeMethods.KEY_READ | SafeNativeMethods.KEY_WOW64_64KEY;

            if (writeable)
            {
                samDesired |= SafeNativeMethods.KEY_WRITE;
            }

            int status = SafeNativeMethods.RegOpenKeyEx(HKEY_LOCAL_MACHINE, subKey, 0, samDesired, out regHandle);

            if (status != SafeNativeMethods.ERROR_SUCCESS || regHandle == null || regHandle.IsInvalid)
            {
                Utility.CloseInvalidOutSafeHandle(regHandle);
                return(null);
            }
            return(regHandle);
        }