本文整理汇总了C#中System.Management.ManagementBaseObject.GetPropertyValue方法的典型用法代码示例。如果您正苦于以下问题:C# ManagementBaseObject.GetPropertyValue方法的具体用法?C# ManagementBaseObject.GetPropertyValue怎么用?C# ManagementBaseObject.GetPropertyValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Management.ManagementBaseObject
的用法示例。
在下文中一共展示了ManagementBaseObject.GetPropertyValue方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetProperty
private static string GetProperty(ManagementBaseObject obj, string property)
{
var value = (obj.GetPropertyValue(property) == null)
? "NA"
: obj.GetPropertyValue(property).ToString();
return value;
}
示例2: GetDevice
private Win32UsbControllerDevice GetDevice(ManagementBaseObject managementObject)
{
try
{
Win32UsbControllerDevice win32UsbControllerDevice = new Win32UsbControllerDevice();
try
{
String dependent = managementObject.GetPropertyValue("Dependent").ToString();
win32UsbControllerDevice.DeviceId = this.ExtractSeviceId(dependent);
}
catch (Exception ex)
{
}
try
{
String antecedent = managementObject.GetPropertyValue("Antecedent").ToString();
win32UsbControllerDevice.ControllerId = this.ExtractSeviceId(antecedent);
}
catch (Exception ex)
{
}
try
{
String locationInformation = this.GetLocationInformation(win32UsbControllerDevice.DeviceId);
Int32 hubIndex = locationInformation.IndexOf("HUB_#", StringComparison.OrdinalIgnoreCase);
Int32 portIndex = locationInformation.IndexOf("PORT_#", StringComparison.OrdinalIgnoreCase);
if ((hubIndex < 0) || (portIndex < 0))
{
throw new Exception("Wrong location information format");
}
win32UsbControllerDevice.Hub = locationInformation.Substring(hubIndex + 5, 4);
win32UsbControllerDevice.Port = locationInformation.Substring(portIndex + 6, 4);
}
catch (Exception ex)
{
}
try
{
Int32 vidIndex = win32UsbControllerDevice.DeviceId.IndexOf("VID", StringComparison.OrdinalIgnoreCase);
Int32 pidIndex = win32UsbControllerDevice.DeviceId.IndexOf("PID", StringComparison.OrdinalIgnoreCase);
if ((vidIndex < 0) || (pidIndex < 0))
{
throw new Exception("Wrong device ID format");
}
win32UsbControllerDevice.Vid = win32UsbControllerDevice.DeviceId.Substring(vidIndex + 4, 4);
win32UsbControllerDevice.Pid = win32UsbControllerDevice.DeviceId.Substring(pidIndex + 4, 4);
}
catch (Exception ex)
{
}
return win32UsbControllerDevice;
}
catch (Exception ex)
{
}
return null;
}
示例3: GetPrinterIP
/// <summary>
/// Get the IP of a printer
/// </summary>
/// <param name="printer"></param>
/// <returns></returns>
private string GetPrinterIP(ManagementBaseObject printer)
{
// Select a Win32_TCPIPPrinterPort with a matching name as the printer's PortName
// This will allow us to get the actual address being used by the port
using (var query = new ManagementObjectSearcher(
$"SELECT * from Win32_TCPIPPrinterPort WHERE Name LIKE \"{printer.GetPropertyValue("PortName")}\""))
{
foreach (var port in query.Get())
return port.GetPropertyValue("HostAddress").ToString();
}
return null;
}
示例4: GetPrinterDriver
/// <summary>
/// Get the path to the inf used by a printer
/// </summary>
/// <param name="printer"></param>
/// <returns></returns>
private string GetPrinterDriver(ManagementBaseObject printer)
{
// Get the name of the driver used by the printer and match it to a Win32_PrinterDriver
var name = printer.GetPropertyValue("DriverName");
using (var query = new ManagementObjectSearcher("SELECT * from Win32_PrinterDriver"))
{
// Select only the drivers which match the naming scheme (driver is in CSV format name,version,32/64bit)
foreach (var driver in from ManagementBaseObject driver
in query.Get()
let info = driver.GetPropertyValue("Name").ToString().Split(',')
where info[0].Equals(name)
select driver)
{
// TODO: Rewrite using ternary or null coalescing
try
{
return Path.Combine(driver.GetPropertyValue("FilePath").ToString(),
driver.GetPropertyValue("InfName").ToString());
}
catch (Exception)
{
return @"C:\Windows\inf\ntprint.inf";
}
}
}
return null;
}
示例5: ProcessPingStatus
private void ProcessPingStatus(ManagementBaseObject pingStatus)
{
string str = (string)LanguagePrimitives.ConvertTo(pingStatus.GetPropertyValue("Address"), typeof(string), CultureInfo.InvariantCulture);
int num = (int)LanguagePrimitives.ConvertTo(pingStatus.GetPropertyValue("PrimaryAddressResolutionStatus"), typeof(int), CultureInfo.InvariantCulture);
if (num == 0)
{
int num1 = (int)LanguagePrimitives.ConvertTo(pingStatus.GetPropertyValue("StatusCode"), typeof(int), CultureInfo.InvariantCulture);
if (num1 == 0)
{
this.quietResults[str] = true;
if (!this.quiet)
{
base.WriteObject(pingStatus);
}
}
else
{
if (!this.quiet)
{
Win32Exception win32Exception = new Win32Exception(num1);
string str1 = StringUtil.Format(ComputerResources.NoPingResult, str, win32Exception.Message);
Exception pingException = new PingException(str1, win32Exception);
ErrorRecord errorRecord = new ErrorRecord(pingException, "TestConnectionException", ErrorCategory.ResourceUnavailable, str);
base.WriteError(errorRecord);
return;
}
}
}
else
{
if (!this.quiet)
{
Win32Exception win32Exception1 = new Win32Exception(num);
string str2 = StringUtil.Format(ComputerResources.NoPingResult, str, win32Exception1.Message);
Exception exception = new PingException(str2, win32Exception1);
ErrorRecord errorRecord1 = new ErrorRecord(exception, "TestConnectionException", ErrorCategory.ResourceUnavailable, str);
base.WriteError(errorRecord1);
return;
}
}
}
示例6: SafeGetProperty
private static string SafeGetProperty(ManagementBaseObject mbo, string key)
{
try {
object o = mbo.GetPropertyValue(key);
if(o != null) {
return o.ToString();
}
} catch {}
return "key is null";
}