/// <summary> /// Returns true if the property is settable /// </summary> /// <param name="property">property to check</param> /// <returns>true if the property is settable</returns> protected override bool PropertyIsSettable(PSProperty property) { ManagementBaseObject mObj = property.baseObject as ManagementBaseObject; try { ManagementClass objClass = CreateClassFrmObject(mObj); return((bool)objClass.GetPropertyQualifierValue(property.Name, "Write")); } catch (ManagementException) { // A property that lacks the Write qualifier may still be writeable. // The provider implementation may allow any properties in the provider // classes to be changed, whether the Write qualifier is present or not. return(true); } catch (UnauthorizedAccessException) { // A property that lacks the Write qualifier may still be writeable. // The provider implementation may allow any properties in the provider // classes to be changed, whether the Write qualifier is present or not. return(true); } catch (System.Runtime.InteropServices.COMException) { // A property that lacks the Write qualifier may still be writeable. // The provider implementation may allow any properties in the provider // classes to be changed, whether the Write qualifier is present or not. return(true); } }
public static void Main() { // Get the WMI class ManagementClass processClass = new ManagementClass("Win32_Process"); processClass.Options.UseAmendedQualifiers = true; // Get the properties in the class PropertyDataCollection properties = processClass.Properties; // display the properties Console.WriteLine("Win32_Process Property Names: "); foreach (PropertyData property in properties) { Console.WriteLine(property.Name); foreach (QualifierData q in property.Qualifiers) { if (q.Name.Equals("Description")) { Console.WriteLine( processClass.GetPropertyQualifierValue( property.Name, q.Name)); } } Console.WriteLine(); } }
public static List <List <String> > getProperties(string pClass) { List <List <String> > result = new List <List <String> >(); ManagementClass processClass = new ManagementClass(pClass); processClass.Options.UseAmendedQualifiers = true; PropertyDataCollection properties = processClass.Properties; foreach (PropertyData prop in properties) { List <String> pResult = new List <String>(); pResult.Add(prop.Name); pResult.Add(prop.Type.ToString()); pResult.Add(prop.Origin); foreach (QualifierData q in prop.Qualifiers) { if (q.Name.Equals("Description")) { pResult.Add((String)processClass.GetPropertyQualifierValue(prop.Name, q.Name)); } } result.Add(pResult); } return(result); }
public void Fun1() { StringBuilder sb = new StringBuilder(); // Get the WMI class ManagementClass processClass = new ManagementClass("Win32_Process"); processClass.Options.UseAmendedQualifiers = true; // Get the properties in the class PropertyDataCollection properties = processClass.Properties; // display the properties sb.AppendLine("Win32_Process Property Names: "); foreach (PropertyData property in properties) { sb.AppendLine(property.Name); foreach (QualifierData q in property.Qualifiers) { if (q.Name.Equals("Description")) { sb.AppendLine( processClass.GetPropertyQualifierValue( property.Name, q.Name).ToString()); } } sb.AppendLine(); } textBox1.AppendText(sb.ToString()); }
public void Set(string ManagementType) { StringBuilder sb = new StringBuilder(); ManagementClass processClass = new ManagementClass(ManagementType); processClass.Options.UseAmendedQualifiers = true; PropertyDataCollection properties = processClass.Properties; sb.AppendLine("Win32_PnPEntity Property Names:"); foreach (PropertyData property in properties) { sb.AppendLine(property.Name); foreach (QualifierData q in property.Qualifiers) { if (q.Name.Equals("Description")) { sb.AppendLine( processClass.GetPropertyQualifierValue( property.Name, q.Name).ToString()); } } } }
/// <summary> /// Update properties table /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void UpdateProperties(object sender, EventArgs e) { if (listBox.SelectedItem == null) { MessageBox.Show(@"No class select", WmiBrowserMain.Name, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } try { // revert in finally block Cursor = Cursors.WaitCursor; listBox.Enabled = false; menuFileCancel.Enabled = contextMenuCancel.Enabled = true; NameToDescription.Clear(); listView.Items.Clear(); listView.Groups.Clear(); textBoxPropertyDesc.Text = null; const string qDescription = "Description"; groupBox3.Text = $@"Class properties: {listBox.Text}"; string className = _wmiClassCollection[listBox.Text].Name; _cts = new CancellationTokenSource(); await Task.Run(() => { ManagementClass processClass = new ManagementClass(className) { Options = { UseAmendedQualifiers = true } }; PropertyDataCollection properties = processClass.Properties; ManagementObjectSearcher searcher = new ManagementObjectSearcher($"SELECT * FROM {className}") { Scope = _scope, }; foreach (var o in searcher.Get()) { var mo = (ManagementObject)o; _cts.Token.ThrowIfCancellationRequested(); ListViewGroup moGroup = new ListViewGroup(mo.Path.RelativePath); Invoke(new Action(() => { listView.Groups.Add(moGroup); })); // fill rows foreach (PropertyData p in properties) { _cts.Token.ThrowIfCancellationRequested(); // Property name string pName = p.Name; // Property value string pValue = default(string); string pCimType = CimTypeToString[p.Type]; if (p.IsArray) { // Array pCimType += "[]"; var array = mo[pName] as Array; if (array != null) { foreach (var a in array) { pValue += $"{a}, "; } } else { pValue = $"{mo[pName]}"; } } else { switch (p.Type) { // Not array case CimType.None: break; case CimType.DateTime: // convert DateTime to handy format string value = mo[pName]?.ToString(); if (false == string.IsNullOrEmpty(value)) { pValue = ManagementDateTimeConverter.ToDateTime(value).ToString(CultureInfo.CurrentCulture); } break; default: pValue = $"{mo[pName]}"; break; } } // Property description foreach (QualifierData q in p.Qualifiers) { _cts.Token.ThrowIfCancellationRequested(); if (q.Name.Equals(qDescription)) { string pDescription = processClass.GetPropertyQualifierValue(pName, qDescription)?.ToString(); NameToDescription[pName] = pDescription?.Replace("\n", Nl); break; } } ListViewItem pItem = new ListViewItem(new[] { pName, pCimType, pValue }) { Group = moGroup }; if ((listView.Items.Count & 1) == 1) { pItem.BackColor = System.Drawing.Color.LightGray; } Invoke(new Action(() => { listView.Items.Add(pItem); })); } } }, _cts.Token); } catch (OperationCanceledException ex) { MessageBox.Show(ex.Message, WmiBrowserMain.Name, MessageBoxButtons.OK, MessageBoxIcon.Information); } finally { menuFileCancel.Enabled = contextMenuCancel.Enabled = false; listBox.Enabled = true; Cursor = Cursors.Default; } }