/// <summary> /// Creates an registry tweak entry in the current addin key /// </summary> /// <param name="addinType">addin type information</param> /// <param name="name">name for the tweak</param> /// <param name="value">value for the tweak</param> /// <param name="throwException">throw exception on error</param> /// <returns>true if key was created otherwise false</returns> protected static bool SetTweakPersistenceEntry(Type addinType, string name, string value, bool throwException) { try { if (null == addinType) { return(false); } RegistryLocationAttribute registry = AttributeHelper.GetRegistryLocationAttribute(addinType); ProgIdAttribute progID = AttributeHelper.GetProgIDAttribute(addinType); MultiRegisterAttribute register = MultiRegisterAttribute.GetAttribute(addinType); if (null == registry) { return(false); } if (null == progID) { return(false); } // my current keyboard miss the logical or. thanks LogiLink foreach (RegisterIn item in register.Products) { RegistryKey regKeyOffice = null; if (registry.Value == RegistrySaveLocation.LocalMachine) { regKeyOffice = Registry.LocalMachine.OpenSubKey(string.Format(_addinOfficeRegistryKey, item.ToString()) + progID.Value, true); } else { regKeyOffice = Registry.CurrentUser.OpenSubKey(string.Format(_addinOfficeRegistryKey, item.ToString()) + progID.Value, true); } if (null == regKeyOffice) { continue; } regKeyOffice.SetValue(name, value); regKeyOffice.Close(); //regKeyOffice.Dispose(); not available in previous .net versions } return(true); } catch (Exception exception) { NetOffice.DebugConsole.Default.WriteException(exception); if (throwException) { throw; } else { return(false); } } }
public static void RegisterFunction(Type type) { MultiRegisterAttribute attribute = MultiRegisterAttribute.GetAttribute(type); string[] product = new string[attribute.Products.Length]; for (int i = 0; i < attribute.Products.Length; i++) { product[i] = String.Format(_addinOfficeRegistryKey, MultiRegisterAttribute.RegistryEntry(attribute.Products[i])); } RegisterHandler.Proceed(type, product, InstallScope.System, OfficeRegisterKeyState.NeedToCreate); }
public static void UnregisterFunction(Type type) { try { MethodInfo registerMethod = null; UnRegisterFunctionAttribute registerAttribute = null; bool registerMethodPresent = AttributeHelper.GetUnRegisterAttribute(type, ref registerMethod, ref registerAttribute); if (registerMethodPresent) { CallDerivedUnRegisterMethod(type, registerMethod, registerAttribute); if (registerAttribute.Value == RegisterMode.Replace) { return; } } ProgIdAttribute progId = AttributeHelper.GetProgIDAttribute(type); RegistryLocationAttribute location = AttributeHelper.GetRegistryLocationAttribute(type); MultiRegisterAttribute attribute = MultiRegisterAttribute.GetAttribute(type); // unregister addin Registry.ClassesRoot.DeleteSubKey(@"CLSID\{" + type.GUID.ToString().ToUpper() + @"}\Programmable", false); foreach (RegisterIn item in attribute.Products) { // unregister addin in office if (location.Value == RegistrySaveLocation.LocalMachine) { Registry.LocalMachine.DeleteSubKey(string.Format(_addinOfficeRegistryKey, item.ToString()) + progId.Value, false); } else { Registry.CurrentUser.DeleteSubKey(string.Format(_addinOfficeRegistryKey, item.ToString()) + progId.Value, false); } } if ((registerMethodPresent) && (registerAttribute.Value == RegisterMode.CallBeforeAndAfter || registerAttribute.Value == RegisterMode.CallAfter)) { registerMethod.Invoke(null, new object[] { type, RegisterCall.CallAfter }); } } catch (System.Exception exception) { NetOffice.DebugConsole.WriteException(exception); RaiseStaticErrorHandlerMethod(type, RegisterErrorMethodKind.UnRegister, exception); } }
private static RegExport RegExportFunction(Type type, int scope, int keyState) { if (null == type) { throw new ArgumentNullException("type"); } InstallScope currentScope = (InstallScope)scope; OfficeRegisterKeyState currentKeyState = (OfficeRegisterKeyState)keyState; MultiRegisterAttribute attribute = MultiRegisterAttribute.GetAttribute(type); string[] product = new string[attribute.Products.Length]; for (int i = 0; i < attribute.Products.Length; i++) { product[i] = MultiRegisterAttribute.RegistryEntry(attribute.Products[i]); } return(RegExportHandler.Proceed(type, new string[] { _addinOfficeRegistryKey }, currentScope, currentKeyState)); }
private static void OptimizedUnregisterFunction(Type type, int scope, int keyState) { if (null == type) { throw new ArgumentNullException("type"); } InstallScope currentScope = (InstallScope)scope; OfficeUnRegisterKeyState currentKeyState = (OfficeUnRegisterKeyState)keyState; MultiRegisterAttribute attribute = MultiRegisterAttribute.GetAttribute(type); string[] product = new string[attribute.Products.Length]; for (int i = 0; i < attribute.Products.Length; i++) { product[i] = String.Format(_addinOfficeRegistryKey, MultiRegisterAttribute.RegistryEntry(attribute.Products[i])); } COMAddinUnRegisterHandler.Proceed(type, product, currentScope, currentKeyState); }
public static void UnregisterFunction(Type type) { try { MultiRegisterAttribute attribute = MultiRegisterAttribute.GetAttribute(type); string[] product = new string[attribute.Products.Length]; for (int i = 0; i < attribute.Products.Length; i++) { product[i] = String.Format(_addinOfficeRegistryKey, MultiRegisterAttribute.RegistryEntry(attribute.Products[i])); } COMAddinUnRegisterHandler.Proceed(type, product, InstallScope.System, OfficeUnRegisterKeyState.NeedToDelete); } catch (Exception exception) { if (!RegisterErrorHandler.RaiseStaticErrorHandlerMethod(type, RegisterErrorMethodKind.UnRegister, new NetOfficeException(exception.Message, exception))) { throw; } } }
public static void RegisterFunction(Type type) { try { MethodInfo registerMethod = null; RegisterFunctionAttribute registerAttribute = null; bool registerMethodPresent = AttributeHelper.GetRegisterAttribute(type, ref registerMethod, ref registerAttribute); if (registerMethodPresent) { CallDerivedRegisterMethod(type, registerMethod, registerAttribute); if (registerAttribute.Value == RegisterMode.Replace) { return; } } GuidAttribute guid = AttributeHelper.GetGuidAttribute(type); ProgIdAttribute progId = AttributeHelper.GetProgIDAttribute(type); RegistryLocationAttribute location = AttributeHelper.GetRegistryLocationAttribute(type); COMAddinAttribute addin = AttributeHelper.GetCOMAddinAttribute(type); MultiRegisterAttribute attribute = MultiRegisterAttribute.GetAttribute(type); Assembly thisAssembly = Assembly.GetAssembly(type); RegistryKey key = Registry.ClassesRoot.CreateSubKey("CLSID\\{" + type.GUID.ToString().ToUpper() + "}\\InprocServer32\\" + GetAssemblyVersionString(type.Assembly)); key.SetValue("CodeBase", thisAssembly.CodeBase); key.Close(); // add bypass key // http://support.microsoft.com/kb/948461 key = Registry.ClassesRoot.CreateSubKey("Interface\\{000C0601-0000-0000-C000-000000000046}"); string defaultValue = key.GetValue("") as string; if (null == defaultValue) { key.SetValue("", "Office .NET Framework Lockback Bypass Key"); } key.Close(); foreach (RegisterIn item in attribute.Products) { // register addin if (location.Value == RegistrySaveLocation.LocalMachine) { Registry.LocalMachine.CreateSubKey(string.Format(_addinOfficeRegistryKey, item.ToString()) + progId.Value); } else { Registry.CurrentUser.CreateSubKey(string.Format(_addinOfficeRegistryKey, item.ToString()) + progId.Value); } RegistryKey regKeyProduct = null; if (location.Value == RegistrySaveLocation.LocalMachine) { regKeyProduct = Registry.LocalMachine.OpenSubKey(string.Format(_addinOfficeRegistryKey, item.ToString()) + progId.Value, true); } else { regKeyProduct = Registry.CurrentUser.OpenSubKey(string.Format(_addinOfficeRegistryKey, item.ToString()) + progId.Value, true); } regKeyProduct.SetValue("LoadBehavior", addin.LoadBehavior); regKeyProduct.SetValue("FriendlyName", addin.Name); regKeyProduct.SetValue("Description", addin.Description); if (-1 != addin.CommandLineSafe) { regKeyProduct.SetValue("CommandLineSafe", addin.CommandLineSafe); } regKeyProduct.Close(); } if ((registerMethodPresent) && (registerAttribute.Value == RegisterMode.CallBeforeAndAfter || registerAttribute.Value == RegisterMode.CallAfter)) { registerMethod.Invoke(null, new object[] { type, RegisterCall.CallAfter }); } } catch (System.Exception exception) { NetOffice.DebugConsole.WriteException(exception); RaiseStaticErrorHandlerMethod(type, RegisterErrorMethodKind.Register, exception); } }