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); }
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); }
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)); }
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); }
internal static extern int RegQueryValueEx(RegistryHandle hKey, String lpValueName, int[] lpReserved, ref int lpType, [Out] byte[] lpData, ref int lpcbData);
internal static extern int RegDeleteKey(RegistryHandle hKey, String lpValueName);
internal static extern int RegEnumKey(RegistryHandle hKey, int index, StringBuilder lpName, ref int len);
internal static extern int RegSetValueEx(RegistryHandle hKey, String lpValueName, int Reserved, int dwType, String val, int cbData);
internal static extern int RegOpenKeyEx(RegistryHandle hKey, String lpSubKey, int ulOptions, int samDesired, out RegistryHandle hkResult);
internal IProxyProvider GetProxyProvider() { if (null == monikerSupportLibrary) { lock (this) { if (null == monikerSupportLibrary) { getCODelegate = null; using (RegistryHandle regKey = RegistryHandle.GetCorrectBitnessHKLMSubkey((IntPtr.Size == 8), ServiceModelInstallStrings.WinFXRegistryKey)) { string file = regKey.GetStringValue(ServiceModelInstallStrings.RuntimeInstallPathName).TrimEnd('\0') + "\\" + fileName; SafeLibraryHandle tempLibrary = UnsafeNativeMethods.LoadLibrary(file); tempLibrary.DoNotFreeLibraryOnRelease(); monikerSupportLibrary = tempLibrary; if (monikerSupportLibrary.IsInvalid) { monikerSupportLibrary.SetHandleAsInvalid(); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ServiceMonikerSupportLoadFailed(file)); } } } } } if (null == getCODelegate) { lock (this) { if (null == getCODelegate) { try { IntPtr procaddr = UnsafeNativeMethods.GetProcAddress(monikerSupportLibrary, functionName); getCODelegate = (DelegateDllGetClassObject)Marshal.GetDelegateForFunctionPointer(procaddr, typeof(DelegateDllGetClassObject)); } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ComPlusProxyProviderException(SR.GetString(SR.FailedProxyProviderCreation), e)); } } } } IClassFactory cf = null; IProxyProvider proxyProvider = null; try { getCODelegate(ClsidProxyInstanceProvider, typeof(IClassFactory).GUID, ref cf); proxyProvider = cf.CreateInstance(null, typeof(IProxyProvider).GUID) as IProxyProvider; Thread.MemoryBarrier(); } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ComPlusProxyProviderException(SR.GetString(SR.FailedProxyProviderCreation), e)); } finally { if (null != cf) { Marshal.ReleaseComObject(cf); cf = null; } } return(proxyProvider); }
public static Type ResolveClsidToType(Guid clsid) { string name = @"software\classes\clsid\{" + clsid.ToString() + @"}\InprocServer32"; using (RegistryKey key = Registry.LocalMachine.OpenSubKey(name, false)) { if (key != null) { using (RegistryKey key2 = key.OpenSubKey(typeof(TypeCacheManager).Assembly.ImageRuntimeVersion)) { string str2 = null; if (key2 == null) { name = null; foreach (string str3 in key.GetSubKeyNames()) { name = str3; if (!string.IsNullOrEmpty(name)) { using (RegistryKey key3 = key.OpenSubKey(name)) { str2 = (string)key3.GetValue("Assembly"); if (!string.IsNullOrEmpty(str2)) { break; } } } } } else { str2 = (string)key2.GetValue("Assembly"); } if (!string.IsNullOrEmpty(str2)) { foreach (Type type in Assembly.Load(str2).GetTypes()) { if (type.IsClass && (type.GUID == clsid)) { return(type); } } } return(null); } } } using (RegistryHandle handle = RegistryHandle.GetBitnessHKCR(IntPtr.Size != 8)) { if (handle != null) { using (RegistryHandle handle2 = handle.OpenSubKey(@"CLSID\{" + clsid.ToString() + @"}\InprocServer32")) { using (RegistryHandle handle3 = handle2.OpenSubKey(typeof(TypeCacheManager).Assembly.ImageRuntimeVersion)) { string stringValue = null; if (handle3 == null) { name = null; foreach (string str in handle2.GetSubKeyNames()) { if (!string.IsNullOrEmpty(str)) { using (RegistryHandle handle4 = handle2.OpenSubKey(str)) { stringValue = handle4.GetStringValue("Assembly"); if (!string.IsNullOrEmpty(stringValue)) { break; } } } } } else { stringValue = handle3.GetStringValue("Assembly"); } if (!string.IsNullOrEmpty(stringValue)) { foreach (Type type2 in Assembly.Load(stringValue).GetTypes()) { if (type2.IsClass && (type2.GUID == clsid)) { return(type2); } } } return(null); } } } } return(null); }
internal IProxyProvider GetProxyProvider() { if (this.monikerSupportLibrary == null) { lock (this) { if (this.monikerSupportLibrary == null) { this.getCODelegate = null; using (RegistryHandle handle = RegistryHandle.GetCorrectBitnessHKLMSubkey(IntPtr.Size == 8, @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Client")) { string libFilename = handle.GetStringValue("InstallPath").TrimEnd(new char[1]) + @"\ServiceMonikerSupport.dll"; this.monikerSupportLibrary = UnsafeNativeMethods.LoadLibrary(libFilename); this.monikerSupportLibrary.DoNotFreeLibraryOnRelease(); if (this.monikerSupportLibrary.IsInvalid) { this.monikerSupportLibrary.SetHandleAsInvalid(); throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ServiceMonikerSupportLoadFailed(libFilename)); } } } } } if (this.getCODelegate == null) { lock (this) { if (this.getCODelegate == null) { try { IntPtr procAddress = UnsafeNativeMethods.GetProcAddress(this.monikerSupportLibrary, "DllGetClassObject"); this.getCODelegate = (DelegateDllGetClassObject)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(DelegateDllGetClassObject)); } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ComPlusProxyProviderException(System.ServiceModel.SR.GetString("FailedProxyProviderCreation"), exception)); } } } } IClassFactory ppv = null; IProxyProvider provider = null; try { this.getCODelegate(ClsidProxyInstanceProvider, typeof(IClassFactory).GUID, ref ppv); provider = ppv.CreateInstance(null, typeof(IProxyProvider).GUID) as IProxyProvider; Thread.MemoryBarrier(); } catch (Exception exception2) { if (Fx.IsFatal(exception2)) { throw; } throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ComPlusProxyProviderException(System.ServiceModel.SR.GetString("FailedProxyProviderCreation"), exception2)); } finally { if (ppv != null) { Marshal.ReleaseComObject(ppv); ppv = null; } } return(provider); }
public static Type ResolveClsidToType(Guid clsid) { string keyName = String.Concat("software\\classes\\clsid\\{", clsid.ToString(), "}\\InprocServer32"); using (RegistryKey clsidKey = Registry.LocalMachine.OpenSubKey(keyName, false)) { if (clsidKey != null) { using (RegistryKey assemblyKey = clsidKey.OpenSubKey(typeof(TypeCacheManager).Assembly.ImageRuntimeVersion)) { string assemblyName = null; if (assemblyKey == null) { keyName = null; foreach (string subKeyName in clsidKey.GetSubKeyNames()) { keyName = subKeyName; if (String.IsNullOrEmpty(keyName)) { continue; } using (RegistryKey assemblyKeyAny = clsidKey.OpenSubKey(keyName)) { assemblyName = (string)assemblyKeyAny.GetValue("Assembly"); if (String.IsNullOrEmpty(assemblyName)) { continue; } else { break; } } } } else { assemblyName = (string)assemblyKey.GetValue("Assembly"); } if (String.IsNullOrEmpty(assemblyName)) { return(null); } Assembly asm = Assembly.Load(assemblyName); foreach (Type type in asm.GetTypes()) { if (type.IsClass && (type.GUID == clsid)) { return(type); } } return(null); } } } // We failed to get the hive information from a native process hive lets go for the alternative bitness using (RegistryHandle hkcr = RegistryHandle.GetBitnessHKCR(IntPtr.Size == 8 ? false : true)) { if (hkcr != null) { using (RegistryHandle clsidKey = hkcr.OpenSubKey(String.Concat("CLSID\\{", clsid.ToString(), "}\\InprocServer32"))) { using (RegistryHandle assemblyKey = clsidKey.OpenSubKey(typeof(TypeCacheManager).Assembly.ImageRuntimeVersion)) { string assemblyName = null; if (assemblyKey == null) { keyName = null; foreach (string subKeyName in clsidKey.GetSubKeyNames()) { keyName = subKeyName; if (String.IsNullOrEmpty(keyName)) { continue; } using (RegistryHandle assemblyKeyAny = clsidKey.OpenSubKey(keyName)) { assemblyName = (string)assemblyKeyAny.GetStringValue("Assembly"); if (String.IsNullOrEmpty(assemblyName)) { continue; } else { break; } } } } else { assemblyName = assemblyKey.GetStringValue("Assembly"); } if (String.IsNullOrEmpty(assemblyName)) { return(null); } Assembly asm = Assembly.Load(assemblyName); foreach (Type type in asm.GetTypes()) { if (type.IsClass && (type.GUID == clsid)) { return(type); } } return(null); } } } } return(null); }