編輯

共用方式為


SelectQuery.QueryString Property

Definition

Gets or sets the query in the SelectQuery object, in string form.

public:
 virtual property System::String ^ QueryString { System::String ^ get(); void set(System::String ^ value); };
public override string QueryString { get; set; }
member this.QueryString : string with get, set
Public Overrides Property QueryString As String

Property Value

Returns a String value containing the query.

Examples

The following example initializes a SelectQuery with the parameterless constructor and then changes the QueryString property.

using System;
using System.Management;

public class Sample
{
    public static void Main(string[] args)
    {
        SelectQuery s = new SelectQuery();
        s.QueryString = "SELECT * FROM Win32_Process";

        ManagementObjectSearcher searcher =
            new ManagementObjectSearcher(
            s);

        foreach (ManagementObject o in searcher.Get())
        {
            // show the class
            Console.WriteLine(o.ToString());
        }
    }
}
Imports System.Management


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

        Dim s As New SelectQuery
        s.QueryString = "SELECT * FROM Win32_Process"

        Dim searcher As ManagementObjectSearcher
        searcher = New ManagementObjectSearcher(s)

        For Each o As ManagementObject In searcher.Get()
            'show the class
            Console.WriteLine(o.ToString())
        Next


    End Function 'Main
End Class

Remarks

Setting this property value overrides any previous value stored in the object. In addition, setting this property causes the other members of the object to be updated when the string is reparsed.

Property Value

A string representing the query.

.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.

Applies to