private void KeyValueChanged(string SubKey, string RegItem, string RegItemValue, RegistryValueKind Type) { object RegItemValueConverted; regMod = new ModifyRegistry(); //Read registry key regMod.RegistryView = RegistryView; regMod.RegistryHive = RegistryHive; //regMod.BaseRegistryKey = BaseRegistryKey; //regMod.BaseRegistryKey = Registry.LocalMachine; regMod.SubKey = SubKey; //regMod.SubKey = "Software\\Test"; var regRead = regMod.Read(RegItem); ////////////////////////////MessageBox.Show("KeyValueChanged: " + regRead); //RegItem = "Test"; //RegItemValue = "098765432"; //MessageBox.Show(regMod.BaseRegistryKey.ToString()); //MessageBox.Show("RegItem: " + RegItem); //MessageBox.Show("SubKey: " + regMod.SubKey); //MessageBox.Show("RegItem: " + RegItem); //MessageBox.Show("RegItemValue: " + RegItemValue); //Convert string value to correct type if (Type == RegistryValueKind.Binary) { int numOfBytes = RegItemValue.Length; byte[] bytes = new byte[numOfBytes / 2]; for (int i = 0; i < numOfBytes / 2; ++i) { bytes[i] = Convert.ToByte(RegItemValue.Substring((i * 2), 2)); } RegItemValueConverted = bytes; } else if (Type == RegistryValueKind.DWord) { RegItemValueConverted = Convert.ToInt32(RegItemValue); } else if (Type == RegistryValueKind.QWord) { RegItemValueConverted = Convert.ToInt64(RegItemValue); } else { RegItemValueConverted = RegItemValue; } if (regRead != null) { regMod.Write(RegItem, RegItemValueConverted, Type);//RegistryValueKind.String } // e.NewEvent. // MessageBox.Show(e.ToString()); //https://lxlexc5.lexel.local/ecp/?rfr=olk&p=customize/voicemail.aspx&exsvurl=1&realm=lexel.co.nz }
/// <summary> /// Check if settings have components that require admin rights, give option to restart as admin /// </summary> private static void RunAsAdminCheck() { //If not already running as admin if (!userAccessControl.IsRunAsAdmin()) { #region Lync Custom Menus //If Lync custom menus are defined check if they need updating bool regRequiresUpdate = false; if (Settings.appSettings.Descendants("CustomMenuItems").Elements("MenuItem").Any()) { ModifyRegistry readKey = new ModifyRegistry(); readKey.RegistryView = RegistryView.Registry32; readKey.RegistryHive = RegistryHive.LocalMachine; readKey.ShowError = true; //Read MenuItems from XML foreach (var CustomMenuItem in Settings.appSettings.Descendants("CustomMenuItems").Descendants("MenuItem")) { readKey.SubKey = "SOFTWARE\\Microsoft\\Office\\15.0\\Lync\\SessionManager\\Apps\\" + CustomMenuItem.Element("GUID").Value; foreach (var CustomMenuItemValue in CustomMenuItem.Elements()) { if (CustomMenuItemValue.Name.ToString() != "GUID") { string regKeyName = CustomMenuItemValue.Name.ToString(); string regSettingsValue = CustomMenuItemValue.Value; string regValue = readKey.Read(regKeyName); //MessageBox.Show("Sval: " + regSettingsValue + Environment.NewLine + "regVal: " + regValue); if (regSettingsValue != regValue) { regRequiresUpdate = true; } } } } } //If Lync custom menus need updating prompt to restart as admin if (regRequiresUpdate) { if (MessageBox.Show( "Application settings have enabled Lync custom menus, however you do not have the required permissions. " + "To enable these settings run the application as admin, or remove this configuration from the applications settings." + Environment.NewLine + Environment.NewLine + "Would you like to restart as admin?", "Error creating Lync custom menus", MessageBoxButtons.YesNo) == DialogResult.Yes) { userAccessControl.Elevate(); } } #endregion Lync Custom Menus } }