ManagementBaseObject.GetPropertyValue(String) 方法

定义

获取某属性值的等效访问器。Gets an equivalent accessor to a property's value.

public:
 System::Object ^ GetPropertyValue(System::String ^ propertyName);
public object GetPropertyValue (string propertyName);
member this.GetPropertyValue : string -> obj
Public Function GetPropertyValue (propertyName As String) As Object

参数

propertyName
String

相关的属性的名称。The name of the property of interest.

返回

指定的属性的值。The value of the specified property.

示例

下面的示例列出了在本地计算机上运行的所有进程的名称。The following example lists all the names of the processes running on the local computer. 代码使用 GetPropertyValue 方法来获取进程名称。The code uses the GetPropertyValue method to get the process names.

using System;
using System.Management;

public class Sample 
{    
    public static void Main() 
    {

        // Get the WMI class
        ManagementClass processClass = 
            new ManagementClass("Win32_Process");

        ManagementObjectCollection classObjects;
        classObjects = processClass.GetInstances();

        foreach (ManagementObject classObject in
            classObjects)
        {
            Console.WriteLine(
                classObject.GetPropertyValue(
                "Name"));
        }
    }
}
Imports System.Management


Class Sample
    Public Overloads Shared Function _
        Main(ByVal args() As String) As Integer

        ' Get the WMI class
        Dim processClass As New ManagementClass( _
            "Win32_Process")

        Dim classObjects As ManagementObjectCollection
        classObjects = processClass.GetInstances()

        For Each classObject As ManagementObject _
            In classObjects

            Console.WriteLine( _
                classObject.GetPropertyValue( _
                    "Name"))

        Next

    End Function
End Class

注解

.NET Framework 安全性.NET Framework Security

对直接调用方的完全信任。Full trust for the immediate caller. 此成员不能由部分信任的代码使用。This member cannot be used by partially trusted code. 有关详细信息,请参阅从部分受信任的代码使用库For more information, see Using Libraries from Partially Trusted Code.

适用于