示例#1
0
        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
        }
示例#2
0
        /// <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
            }
        }
示例#3
0
文件: Lync.cs 项目: UCGeeks/UCExtend
        public static void CreateLyncMenu()
        {
            //Get UAC status
            UserAccessControl uacLyncMenu = new UserAccessControl();

            try
            {
                if (Settings.appSettings.Descendants("CustomMenuItems").Elements("MenuItem").Any())
                {
                    ////Request to elevate if required
                    //if (!uacLyncMenu.IsRunAsAdmin())
                    //{
                    //    if (MessageBox.Show("Application settings have enabled Lync custom menus, however you do not have the required permissions. To avoid seeing this message again run the application as admin, or remove this configuration from application settings." + Environment.NewLine + Environment.NewLine + "Would you like to restart as admin?", "Error creating Lync custom menus", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                    //    {
                    //        uacLyncMenu.Elevate();
                    //    }
                    //    else
                    //    {
                    //        return;
                    //    }
                    //}

                    if (uacLyncMenu.IsRunAsAdmin())
                    {
                        //Read MenuItems from XML
                        foreach (var CustomMenuItem in Settings.appSettings.Descendants("CustomMenuItems").Descendants("MenuItem"))
                        {
                            //string GUID = CustomMenuItem.Element("GUID").Value;
                            //string extensibleMenu = CustomMenuItem.Element("ExtensibleMenu").Value;
                            //string name = CustomMenuItem.Element("Name").Value;
                            //string path = CustomMenuItem.Element("Path").Value;

                            //MessageBox.Show(GUID + extensibleMenu + name + path);

                            //Write registry entry
                            //string regSubKey = "Software\\Test\\" + CustomMenuItem.Element("GUID").Value;
                            string regSubKey = "SOFTWARE\\Microsoft\\Office\\15.0\\Lync\\SessionManager\\Apps\\" + CustomMenuItem.Element("GUID").Value;

                            foreach (var CustomMenuItemValue in CustomMenuItem.Elements())
                            {
                                if (CustomMenuItemValue.Name.ToString() != "GUID")
                                {
                                    //If Reg kind REG_SZ
                                    if (CustomMenuItemValue.Name == "ExtensibleMenu" ||
                                        CustomMenuItemValue.Name == "Path" ||
                                        CustomMenuItemValue.Name == "Name" ||
                                        CustomMenuItemValue.Name == "ApplicationInstallPath")
                                    {
                                        if (CustomMenuItemValue.Value != null || CustomMenuItemValue.Value != "")
                                        {
                                            //MessageBox.Show(CustomMenuItemValue.Name.ToString() + ":" + CustomMenuItemValue.Value.ToString());
                                            ModifyRegistry addKey = new ModifyRegistry();

                                            addKey.RegistryView = RegistryView.Registry32; //specifies to use the x64 registry node for x32 application. If you request a 64-bit view on a 32-bit operating system, the returned keys will be in the 32-bit view.
                                            addKey.RegistryHive = RegistryHive.LocalMachine;
                                            addKey.ShowError    = true;

                                            string regKeyName = CustomMenuItemValue.Name.ToString();
                                            string regValue   = CustomMenuItemValue.Value.ToString();
                                            addKey.SubKey = regSubKey;

                                            addKey.Write(regKeyName, regValue, RegistryValueKind.String);
                                        }
                                    }
                                    //If Reg kind DWORD
                                    else if (CustomMenuItemValue.Name == "ApplicationType" ||
                                             CustomMenuItemValue.Name == "SessionType")
                                    {
                                        if (CustomMenuItemValue.Value != null || CustomMenuItemValue.Value != "")
                                        {
                                            ModifyRegistry addKey = new ModifyRegistry();

                                            addKey.RegistryView = RegistryView.Registry32; //specifies to use the x64 registry node for x32 application. If you request a 64-bit view on a 32-bit operating system, the returned keys will be in the 32-bit view.
                                            addKey.RegistryHive = RegistryHive.LocalMachine;
                                            addKey.ShowError    = true;

                                            string regKeyName = CustomMenuItemValue.Name.ToString();
                                            string regValue   = CustomMenuItemValue.Value.ToString();
                                            addKey.SubKey = regSubKey;

                                            addKey.Write(regKeyName, regValue, RegistryValueKind.DWord);
                                        }
                                    }
                                }

                                //Add Application Type
                                //ModifyRegistry addKeyAppType = new ModifyRegistry();
                                //addKeyAppType.RegistryView = RegistryView.Registry32;
                                //addKeyAppType.RegistryHive = RegistryHive.LocalMachine;
                                //addKeyAppType.SubKey = regSubKey;
                                //addKeyAppType.ShowError = true;
                                //addKeyAppType.Write("ApplicationType", 1, RegistryValueKind.DWord);
                            }

                            #region No longer required
                            //Read Lync custom menu items from XML
                            //Delete the existing menu items
                            //Read existing subkeys
                            //ModifyRegistry readChildSubKeys = new ModifyRegistry();
                            //readChildSubKeys.RegistryView = RegistryView.Registry64;//specifies to use the x64 registry node for x32 application. If you request a 64-bit view on a 32-bit operating system, the returned keys will be in the 32-bit view.
                            //readChildSubKeys.RegistryHive = RegistryHive.LocalMachine;
                            //readChildSubKeys.SubKey = "Software\\Test";
                            //readChildSubKeys.ShowError = true;
                            //string[] xxxx = readChildSubKeys.ReadChildSubKeys();

                            //foreach (var item in xxxx)
                            //{
                            //Delete found subkeys
                            //MessageBox.Show(item);
                            //}

                            //ModifyRegistry deleteKey = new ModifyRegistry();
                            //deleteKey.RegistryView = RegistryView.Registry64;//specifies to use the x64 registry node for x32 application. If you request a 64-bit view on a 32-bit operating system, the returned keys will be in the 32-bit view.
                            //deleteKey.RegistryHive = RegistryHive.LocalMachine;
                            //deleteKey.SubKey = "Software\\Test";
                            //deleteKey.ShowError = true;
                            //deleteKey.DeleteSubKeyTree();

                            //Generate GUID
                            //Guid id = Guid.NewGuid();
                            #endregion OLD
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //AAAAAAAAAAARGH, an error!
                Shared.MB("Error adding Lync custom menus : " + ex.Message, "ERROR!");
            }
        }
示例#4
0
        private void buttonSaveSettings_Click(object sender, EventArgs e)
        {
            SettingsSavedTime = DateTime.Now;

            //Presense switcher check boxes
            if (checkBoxPresenceSwitcher1.Checked == true)
            {
                Settings.PsEnabled1 = "true";
            }
            else
            {
                Settings.PsEnabled1 = "false";
            }
            if (checkBoxPresenceSwitcher2.Checked == true)
            {
                Settings.PsEnabled2 = "true";
            }
            else
            {
                Settings.PsEnabled2 = "false";
            }
            if (checkBoxPresenceSwitcher3.Checked == true)
            {
                Settings.PsEnabled3 = "true";
            }
            else
            {
                Settings.PsEnabled3 = "false";
            }
            if (checkBoxPresenceSwitcher4.Checked == true)
            {
                Settings.PsEnabled4 = "true";
            }
            else
            {
                Settings.PsEnabled4 = "false";
            }
            if (checkBoxPresenceSwitcherDay.Checked == true)
            {
                Settings.PsEnabled5 = "true";
            }
            else
            {
                Settings.PsEnabled5 = "false";
            }

            //From
            Settings.PsFromTime1 = dateTimePickerFromPresenceSwitcher1.Value.TimeOfDay.ToString();
            Settings.PsFromTime2 = dateTimePickerFromPresenceSwitcher2.Value.TimeOfDay.ToString();
            Settings.PsFromTime3 = dateTimePickerFromPresenceSwitcher3.Value.TimeOfDay.ToString();
            Settings.PsFromTime4 = dateTimePickerFromPresenceSwitcher4.Value.TimeOfDay.ToString();

            //To
            Settings.PsToTime1 = dateTimePickerToPresenceSwitcher1.Value.TimeOfDay.ToString();
            Settings.PsToTime2 = dateTimePickerToPresenceSwitcher2.Value.TimeOfDay.ToString();
            Settings.PsToTime3 = dateTimePickerToPresenceSwitcher3.Value.TimeOfDay.ToString();
            Settings.PsToTime4 = dateTimePickerToPresenceSwitcher4.Value.TimeOfDay.ToString();

            //Availability
            Settings.PsAvailability1 = comboBoxPresenceSwitcher1.Text;
            Settings.PsAvailability2 = comboBoxPresenceSwitcher2.Text;
            Settings.PsAvailability3 = comboBoxPresenceSwitcher3.Text;
            Settings.PsAvailability4 = comboBoxPresenceSwitcher4.Text;
            Settings.PsAvailability5 = comboBoxPresenceSwitcherDay.Text;

            //PersonalNote
            Settings.PsPersonalNote1 = textBoxPresenceSwitcher1.Text;
            Settings.PsPersonalNote2 = textBoxPresenceSwitcher2.Text;
            Settings.PsPersonalNote3 = textBoxPresenceSwitcher3.Text;
            Settings.PsPersonalNote4 = textBoxPresenceSwitcher4.Text;
            Settings.PsPersonalNote5 = textBoxPresenceSwitcherDay.Text;

            //Days of Week
            _selectedDaysOfWeek = new List <string>();

            if (checkBoxSettingsMonday.Checked)
            {
                _selectedDaysOfWeek.Add("Monday");
            }
            if (checkBoxSettingsTuesday.Checked)
            {
                _selectedDaysOfWeek.Add("Tuesday");
            }
            if (checkBoxSettingsWednesday.Checked)
            {
                _selectedDaysOfWeek.Add("Wednesday");
            }
            if (checkBoxSettingsThursday.Checked)
            {
                _selectedDaysOfWeek.Add("Thursday");
            }
            if (checkBoxSettingsFriday.Checked)
            {
                _selectedDaysOfWeek.Add("Friday");
            }
            if (checkBoxSettingsSaturday.Checked)
            {
                _selectedDaysOfWeek.Add("Saturday");
            }
            if (checkBoxSettingsSunday.Checked)
            {
                _selectedDaysOfWeek.Add("Sunday");
            }
            Settings.PsSelectedDaysOfWeek5 = (string.Join(",", _selectedDaysOfWeek));


            //Set Me As
            if (checkBoxSettingsLyncSetMeAs1.Checked == true)
            {
                Settings.PsSetMeAsEnabled1 = "true";
            }
            else
            {
                Settings.PsSetMeAsEnabled1 = "false";
            }
            if (checkBoxSettingsLyncSetMeAs2.Checked == true)
            {
                Settings.PsSetMeAsEnabled2 = "true";
            }
            else
            {
                Settings.PsSetMeAsEnabled2 = "false";
            }

            Settings.PsSetMeAsAvailability1 = comboBoxSettingsLyncSetMeAs1.Text;
            Settings.PsSetMeAsTime1         = numericUpDownSettingsLyncSetMeAs1.Value.ToString();

            Settings.PsSetMeAsAvailability2 = comboBoxSettingsLyncSetMeAs2.Text;
            Settings.PsSetMeAsTime2         = numericUpDownSettingsLyncSetMeAs2.Value.ToString();


            //EnableSkypeUI - One off change when user saves settings (not saved in settings or enforced after save)
            ModifyRegistry enableSkypeUI = new ModifyRegistry();

            enableSkypeUI.RegistryView = RegistryView.Registry32; //specifies to use the x64 registry node for x32 application. If you request a 64-bit view on a 32-bit operating system, the returned keys will be in the 32-bit view.
            enableSkypeUI.RegistryHive = RegistryHive.CurrentUser;
            enableSkypeUI.ShowError    = true;
            string regKeyName = "EnableSkypeUI";

            enableSkypeUI.SubKey = "SOFTWARE\\Microsoft\\Office\\Lync";

            if (radioButtonSkypeUIFalse.Checked)
            {
                enableSkypeUI.Write(regKeyName, new byte[] { 00, 00, 00, 00 }, RegistryValueKind.Binary);
            }
            else if (radioButtonSkypeUITrue.Checked)
            {
                enableSkypeUI.Write(regKeyName, new byte[] { 01, 00, 00, 00 }, RegistryValueKind.Binary);
            }

            labelSettingsSavedTime.Text = "Saved Time: " + SettingsSavedTime.ToString("dd-MM-yyyy HH:mm:ss");
        }