示例#1
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            WMIQuery W = Program.Settings.WMIQueries.Find(WMIQuery => WMIQuery.Name == (string)listQueries.SelectedItem);

            Program.Settings.WMIQueries.Remove(W);
            listQueries.Items.RemoveAt(listQueries.SelectedIndex);
        }
示例#2
0
        /// <summary>
        /// Executes and returns the result of the WMI query nominated by ID. The list of known IDs is
        /// stored in Program.Settings so it can be saved and restored
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        private string[] ExecWMIQuery(string ID)
        {
            // Find the query in the list of known queries
            WMIQuery W = Program.Settings.WMIQueries.Find(WMIQuery => WMIQuery.Name == ID);

            try
            {
                using (var WMI = new ManagementObjectSearcher(W.Namespace, W.Query))
                {
                    List <string> Values = new List <string>();
                    foreach (ManagementObject Result in WMI.Get())
                    {
                        foreach (var pDC in Result.Properties)
                        {
                            Values.Add(pDC.Value.ToString());
                        }
                    }
                    return(Values.ToArray());
                }
            }
            catch (Exception e)
            {
                return(new string[] { "WMI Query " + ID + " failed - " + e.Message });
            }
        }
示例#3
0
        /// <summary>
        /// Implement the ICloneable interface
        /// </summary>
        /// <returns></returns>
        public object Clone()
        {
            WMIQuery clone = new WMIQuery();
            clone.Name = Name.Clone() as string;
            clone.Namespace = Namespace.Clone() as string;
            clone.Query = Query.Clone() as string;

            return clone;
        }
示例#4
0
        /// <summary>
        /// Implement the ICloneable interface
        /// </summary>
        /// <returns></returns>
        public object Clone()
        {
            WMIQuery clone = new WMIQuery();

            clone.Name      = Name.Clone() as string;
            clone.Namespace = Namespace.Clone() as string;
            clone.Query     = Query.Clone() as string;

            return(clone);
        }
示例#5
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     WMIQuery oldW = Program.Settings.WMIQueries.Find(WMIQuery => WMIQuery.Name == (string)listQueries.SelectedItem);
     WMIQuery W = new WMIQuery();
     W.Name = txtName.Text;
     W.Namespace = txtNamespace.Text;
     W.Query = txtQuery.Text;
     if (oldW != null) Program.Settings.WMIQueries.Remove(oldW);
     Program.Settings.WMIQueries.Add(W);
     if ((oldW != null) && (oldW.Name != W.Name))
         listQueries.Items.RemoveAt(listQueries.SelectedIndex);
     else if ((oldW == null) || (oldW.Name != W.Name))
         listQueries.Items.Add(txtName.Text);
     listQueries.SelectedIndex = listQueries.Items.IndexOf(txtName.Text);
     listQueries_SelectedIndexChanged(sender, e);        // Force refresh to "not editing" state
 }
示例#6
0
 private void listQueries_SelectedIndexChanged(object sender, EventArgs e)
 {
     txtName.Enabled      = false; txtName.ReadOnly = true;
     txtNamespace.Enabled = false; txtNamespace.ReadOnly = true;
     txtQuery.Enabled     = false; txtQuery.ReadOnly = true;
     if (listQueries.SelectedItem != null)
     {
         WMIQuery W = Program.Settings.WMIQueries.Find(WMIQuery => WMIQuery.Name == (string)listQueries.SelectedItem);
         btnEdit.Enabled   = true;
         btnDelete.Enabled = true;
         txtName.Text      = W.Name;
         txtNamespace.Text = W.Namespace;
         txtQuery.Text     = W.Query;
     }
     else
     {
         btnEdit.Enabled   = false;
         btnDelete.Enabled = false;
         txtName.Text      = WMIQuery.Defaults.Name;
         txtNamespace.Text = WMIQuery.Defaults.Namespace;
         txtQuery.Text     = WMIQuery.Defaults.Query;
     }
 }
示例#7
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            WMIQuery oldW = Program.Settings.WMIQueries.Find(WMIQuery => WMIQuery.Name == (string)listQueries.SelectedItem);
            WMIQuery W    = new WMIQuery();

            W.Name      = txtName.Text;
            W.Namespace = txtNamespace.Text;
            W.Query     = txtQuery.Text;
            if (oldW != null)
            {
                Program.Settings.WMIQueries.Remove(oldW);
            }
            Program.Settings.WMIQueries.Add(W);
            if ((oldW != null) && (oldW.Name != W.Name))
            {
                listQueries.Items.RemoveAt(listQueries.SelectedIndex);
            }
            else if ((oldW == null) || (oldW.Name != W.Name))
            {
                listQueries.Items.Add(txtName.Text);
            }
            listQueries.SelectedIndex = listQueries.Items.IndexOf(txtName.Text);
            listQueries_SelectedIndexChanged(sender, e);        // Force refresh to "not editing" state
        }