private void cmdOK_Click(object sender, EventArgs e) { if (DoValidate()) { SelectedRegistryQueryInstance.Name = txtName.Text; SelectedRegistryQueryInstance.UseRemoteServer = chkUseRemoteServer.Checked; SelectedRegistryQueryInstance.Server = txtServer.Text; SelectedRegistryQueryInstance.Path = txtPath.Text; SelectedRegistryQueryInstance.KeyName = txtKey.Text; SelectedRegistryQueryInstance.ExpandEnvironmentNames = chkExpandEnvNames.Checked; SelectedRegistryQueryInstance.RegistryHive = RegistryQueryInstance.GetRegistryHiveFromString(cboRegistryHive.Text); if (!chkValueIsANumber.Checked) { SelectedRegistryQueryInstance.ReturnValueIsNumber = false; SelectedRegistryQueryInstance.ReturnValueInARange = false; SelectedRegistryQueryInstance.ReturnValueInverted = false; } else { SelectedRegistryQueryInstance.ReturnValueIsNumber = true; SelectedRegistryQueryInstance.ReturnValueInARange = chkValueIsInARange.Checked; SelectedRegistryQueryInstance.ReturnValueInverted = !chkReturnValueNotInverted.Checked; } SelectedRegistryQueryInstance.SuccessValue = cboSuccessValue.Text; SelectedRegistryQueryInstance.WarningValue = cboWarningValue.Text; SelectedRegistryQueryInstance.ErrorValue = cboErrorValue.Text; DialogResult = System.Windows.Forms.DialogResult.OK; Close(); } }
private void cmdTest_Click(object sender, EventArgs e) { if (DoValidate()) { string lastStep = "Initialize values"; try { Cursor.Current = Cursors.WaitCursor; RegistryQueryInstance testQueryInstance = new RegistryQueryInstance(); testQueryInstance.Name = txtName.Text; testQueryInstance.UseRemoteServer = chkUseRemoteServer.Checked; testQueryInstance.Server = txtServer.Text; testQueryInstance.Path = txtPath.Text; testQueryInstance.KeyName = txtKey.Text; testQueryInstance.ExpandEnvironmentNames = chkExpandEnvNames.Checked; testQueryInstance.RegistryHive = RegistryQueryInstance.GetRegistryHiveFromString(cboRegistryHive.Text); if (!chkValueIsANumber.Checked) { testQueryInstance.ReturnValueIsNumber = false; testQueryInstance.ReturnValueInARange = false; testQueryInstance.ReturnValueInverted = false; } else { testQueryInstance.ReturnValueIsNumber = true; testQueryInstance.ReturnValueInARange = chkValueIsInARange.Checked; testQueryInstance.ReturnValueInverted = !chkReturnValueNotInverted.Checked; } testQueryInstance.SuccessValue = cboSuccessValue.Text; testQueryInstance.WarningValue = cboWarningValue.Text; testQueryInstance.ErrorValue = cboErrorValue.Text; object returnValue = null; returnValue = testQueryInstance.GetValue(); MonitorStates state = testQueryInstance.EvaluateValue(returnValue); if (state == MonitorStates.Good) { MessageBox.Show(string.Format("Success!\r\nValue return: {0}", returnValue), "Test", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (state == MonitorStates.Warning) { MessageBox.Show(string.Format("Warning!\r\nValue return: {0}", returnValue), "Test", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { MessageBox.Show(string.Format("Error!\r\nValue return: {0}", returnValue), "Test", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show(string.Format("Failed!\r\nLast step: {0}\r\n{1}", lastStep, ex.Message), "Test", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } finally { Cursor.Current = Cursors.Default; } } }
public void ReadConfiguration(XmlDocument config) { XmlElement root = config.DocumentElement; Queries.Clear(); foreach (XmlElement queryNode in root.SelectNodes("queries/query")) { RegistryQueryInstance queryEntry = new RegistryQueryInstance(); queryEntry.Name = queryNode.ReadXmlElementAttr("name", ""); queryEntry.UseRemoteServer = bool.Parse(queryNode.ReadXmlElementAttr("useRemoteServer", "False")); queryEntry.Server = queryNode.ReadXmlElementAttr("server", ""); queryEntry.RegistryHive = RegistryQueryInstance.GetRegistryHiveFromString(queryNode.ReadXmlElementAttr("registryHive", "")); queryEntry.Path = queryNode.ReadXmlElementAttr("path", ""); queryEntry.KeyName = queryNode.ReadXmlElementAttr("keyName", ""); queryEntry.ExpandEnvironmentNames = bool.Parse(queryNode.ReadXmlElementAttr("expandEnvironmentNames", "False")); queryEntry.ReturnValueIsNumber = bool.Parse(queryNode.ReadXmlElementAttr("returnValueIsNumber", "False")); queryEntry.SuccessValue = queryNode.ReadXmlElementAttr("successValue", ""); queryEntry.WarningValue = queryNode.ReadXmlElementAttr("warningValue", ""); queryEntry.ErrorValue = queryNode.ReadXmlElementAttr("errorValue", ""); queryEntry.ReturnValueInARange = bool.Parse(queryNode.ReadXmlElementAttr("returnValueInARange", "False")); queryEntry.ReturnValueInverted = bool.Parse(queryNode.ReadXmlElementAttr("returnValueInverted", "False")); Queries.Add(queryEntry); } }
private void txtPath_Leave(object sender, EventArgs e) { if (txtPath.Text.Length > 0 && txtPath.Text.ToUpper().StartsWith("HKEY_")) { string[] parts = txtPath.Text.Split('\\'); if (parts.Length > 1) { Microsoft.Win32.RegistryHive rh = RegistryQueryInstance.GetRegistryHiveFromString(parts[0]); cboRegistryHive.Text = rh.ToString(); txtPath.Text = txtPath.Text.Substring(parts[0].Length + 1); } } }
private void cmdOK_Click(object sender, EventArgs e) { if (CheckOKEnabled()) { SelectedRegistryQueryConfig = new RegistryQueryConfig(); foreach (ListViewItem lvi in lvwQueries.Items) { RegistryQueryInstance queryInstance = (RegistryQueryInstance)lvi.Tag; SelectedRegistryQueryConfig.Queries.Add(queryInstance); } DialogResult = System.Windows.Forms.DialogResult.OK; Close(); } }
private void LoadList() { if (SelectedRegistryQueryConfig != null) { lvwQueries.Items.Clear(); foreach (RegistryQueryInstance queryInstance in SelectedRegistryQueryConfig.Queries) { ListViewItem lvi = new ListViewItem(queryInstance.Name); lvi.SubItems.Add((queryInstance.UseRemoteServer ? queryInstance.Server + "\\" : "") + RegistryQueryInstance.GetRegistryHiveFromString(queryInstance.RegistryHive.ToString()).ToString() + "\\" + queryInstance.Path); lvi.SubItems.Add(queryInstance.KeyName); lvi.SubItems.Add(queryInstance.SuccessValue); lvi.SubItems.Add(queryInstance.WarningValue); lvi.SubItems.Add(queryInstance.ErrorValue); lvi.Tag = queryInstance; lvwQueries.Items.Add(lvi); } CheckOKEnabled(); } }
private void editToolStripButton_Click(object sender, EventArgs e) { if (lvwQueries.SelectedItems.Count > 0 && lvwQueries.SelectedItems[0].Tag is RegistryQueryInstance) { EditRegistryQueryInstance editQueryInstance = new EditRegistryQueryInstance(); editQueryInstance.SelectedRegistryQueryInstance = (RegistryQueryInstance)lvwQueries.SelectedItems[0].Tag; if (editQueryInstance.ShowDialog() == System.Windows.Forms.DialogResult.OK) { ListViewItem lvi = lvwQueries.SelectedItems[0]; lvi.Text = editQueryInstance.SelectedRegistryQueryInstance.Name; lvi.SubItems[1].Text = (editQueryInstance.SelectedRegistryQueryInstance.UseRemoteServer ? editQueryInstance.SelectedRegistryQueryInstance.Server + "\\" : "") + RegistryQueryInstance.GetRegistryHiveFromString(editQueryInstance.SelectedRegistryQueryInstance.RegistryHive.ToString()).ToString() + "\\" + editQueryInstance.SelectedRegistryQueryInstance.Path; lvi.SubItems[2].Text = editQueryInstance.SelectedRegistryQueryInstance.KeyName; lvi.SubItems[3].Text = editQueryInstance.SelectedRegistryQueryInstance.SuccessValue; lvi.SubItems[4].Text = editQueryInstance.SelectedRegistryQueryInstance.WarningValue; lvi.SubItems[5].Text = editQueryInstance.SelectedRegistryQueryInstance.ErrorValue; lvi.Tag = editQueryInstance.SelectedRegistryQueryInstance; } } }
private void addToolStripButton_Click(object sender, EventArgs e) { EditRegistryQueryInstance editQueryInstance = new EditRegistryQueryInstance(); editQueryInstance.SelectedRegistryQueryInstance = new RegistryQueryInstance(); if (editQueryInstance.ShowDialog() == System.Windows.Forms.DialogResult.OK) { ListViewItem lvi = new ListViewItem(editQueryInstance.SelectedRegistryQueryInstance.Name); lvi.SubItems.Add((editQueryInstance.SelectedRegistryQueryInstance.UseRemoteServer ? editQueryInstance.SelectedRegistryQueryInstance.Server + "\\" : "") + RegistryQueryInstance.GetRegistryHiveFromString(editQueryInstance.SelectedRegistryQueryInstance.RegistryHive.ToString()).ToString() + "\\" + editQueryInstance.SelectedRegistryQueryInstance.Path); lvi.SubItems.Add(editQueryInstance.SelectedRegistryQueryInstance.KeyName); lvi.SubItems.Add(editQueryInstance.SelectedRegistryQueryInstance.SuccessValue); lvi.SubItems.Add(editQueryInstance.SelectedRegistryQueryInstance.WarningValue); lvi.SubItems.Add(editQueryInstance.SelectedRegistryQueryInstance.ErrorValue); lvi.Tag = editQueryInstance.SelectedRegistryQueryInstance; lvwQueries.Items.Add(lvi); CheckOKEnabled(); CheckButtonsEnable(); } }
private void LoadList() { if (SelectedRegistryQueryConfig != null) { lvwDetails.Items.Clear(); foreach (RegistryQueryInstance rq in SelectedRegistryQueryConfig.Queries) { ListViewItem lvi = new ListViewItem(rq.Name); lvi.SubItems.Add((rq.UseRemoteServer ? "[" + rq.Server + "]\\" : "") + RegistryQueryInstance.GetRegistryHiveFromString(rq.RegistryHive.ToString()).ToString() + "\\" + rq.Path + "\\@[" + rq.KeyName + "]"); lvi.SubItems.Add("-"); lvi.Tag = rq; lvwDetails.Items.Add(lvi); } } RefreshList(); }
private void RefreshList() { try { lvwDetails.BeginUpdate(); if (SelectedRegistryQueryConfig != null) { foreach (ListViewItem lvi in lvwDetails.Items) { if (lvi.Tag is RegistryQueryInstance) { RegistryQueryInstance rq = (RegistryQueryInstance)lvi.Tag; try { object value = rq.GetValue(); MonitorStates currentState = rq.EvaluateValue(value); if (value == null) { lvi.SubItems[2].Text = "Null"; } else { lvi.SubItems[2].Text = value.ToString(); } if (currentState == MonitorStates.Good) { lvi.ImageIndex = 0; lvi.BackColor = SystemColors.Window; } else if (currentState == MonitorStates.Warning) { lvi.ImageIndex = 1; lvi.BackColor = Color.SandyBrown; } else { lvi.ImageIndex = 2; lvi.BackColor = Color.Salmon; } } catch (Exception ex) { lvi.SubItems[2].Text = ex.Message; lvi.ImageIndex = 2; lvi.BackColor = Color.Salmon; } } } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { lvwDetails.EndUpdate(); toolStripStatusLabel1.Text = "Last updated " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); } }