Modifica

Condividi tramite


ManagementObjectSearcher Constructors

Definition

Initializes a new instance of the ManagementObjectSearcher class.

Overloads

ManagementObjectSearcher()

Initializes a new instance of the ManagementObjectSearcher class. After some properties on this object are set, the object can be used to invoke a query for management information. This is the parameterless constructor.

ManagementObjectSearcher(ObjectQuery)

Initializes a new instance of the ManagementObjectSearcher class used to invoke the specified query for management information.

ManagementObjectSearcher(String)

Initializes a new instance of the ManagementObjectSearcher class used to invoke the specified query for management information.

ManagementObjectSearcher(ManagementScope, ObjectQuery)

Initializes a new instance of the ManagementObjectSearcher class used to invoke the specified query in the specified scope.

ManagementObjectSearcher(String, String)

Initializes a new instance of the ManagementObjectSearcher class used to invoke the specified query in the specified scope.

ManagementObjectSearcher(ManagementScope, ObjectQuery, EnumerationOptions)

Initializes a new instance of the ManagementObjectSearcher class to be used to invoke the specified query in the specified scope, with the specified options.

ManagementObjectSearcher(String, String, EnumerationOptions)

Initializes a new instance of the ManagementObjectSearcher class used to invoke the specified query, in the specified scope, and with the specified options.

ManagementObjectSearcher()

Source:
ManagementObjectSearcher.cs
Source:
ManagementObjectSearcher.cs
Source:
ManagementObjectSearcher.cs
Source:
ManagementObjectSearcher.cs

Initializes a new instance of the ManagementObjectSearcher class. After some properties on this object are set, the object can be used to invoke a query for management information. This is the parameterless constructor.

public:
 ManagementObjectSearcher();
public ManagementObjectSearcher ();
Public Sub New ()

Remarks

.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

ManagementObjectSearcher(ObjectQuery)

Source:
ManagementObjectSearcher.cs
Source:
ManagementObjectSearcher.cs
Source:
ManagementObjectSearcher.cs
Source:
ManagementObjectSearcher.cs

Initializes a new instance of the ManagementObjectSearcher class used to invoke the specified query for management information.

public:
 ManagementObjectSearcher(System::Management::ObjectQuery ^ query);
public ManagementObjectSearcher (System.Management.ObjectQuery query);
new System.Management.ManagementObjectSearcher : System.Management.ObjectQuery -> System.Management.ManagementObjectSearcher
Public Sub New (query As ObjectQuery)

Parameters

query
ObjectQuery

An ObjectQuery representing the query to be invoked by the searcher.

Examples

The following example initializes a new instance of the ManagementObjectSearcher class with a specific query.

using System;
using System.Management;

public class Sample
{
    public static void Main(string[] args)
    {
        SelectQuery q =
            new SelectQuery("Win32_Service",
                "State='Running'");
        ManagementObjectSearcher s =
            new ManagementObjectSearcher(q);

        foreach (ManagementObject service in s.Get())
        {
            // show the instance
            Console.WriteLine(service.ToString());
        }
    }
}
Imports System.Management


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

        Dim q As New _
            SelectQuery("Win32_Service", "State=""Running""")
        Dim s As New ManagementObjectSearcher(q)

        For Each service As ManagementObject In s.Get()
            'show the instance
            Console.WriteLine(service.ToString())
        Next


    End Function 'Main
End Class

Remarks

.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

ManagementObjectSearcher(String)

Source:
ManagementObjectSearcher.cs
Source:
ManagementObjectSearcher.cs
Source:
ManagementObjectSearcher.cs
Source:
ManagementObjectSearcher.cs

Initializes a new instance of the ManagementObjectSearcher class used to invoke the specified query for management information.

public:
 ManagementObjectSearcher(System::String ^ queryString);
public ManagementObjectSearcher (string queryString);
new System.Management.ManagementObjectSearcher : string -> System.Management.ManagementObjectSearcher
Public Sub New (queryString As String)

Parameters

queryString
String

The WMI query to be invoked by the object.

Examples

The following example initializes a new instance of the ManagementObjectSearcher class with a specific query.

using System;
using System.Management;

public class Sample
{
    public static void Main(string[] args)
    {
        ManagementObjectSearcher s =
            new ManagementObjectSearcher(
                "SELECT * FROM Win32_Service");

        foreach (ManagementObject service in s.Get())
        {
            // show the instance
            Console.WriteLine(service.ToString());
        }
    }
}
Imports System.Management


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

        Dim s As New _
            ManagementObjectSearcher( _
            "SELECT * FROM Win32_Service")

        For Each service As ManagementObject In s.Get()
            'show the instance
            Console.WriteLine(service.ToString())
        Next


    End Function 'Main
End Class

Remarks

.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

ManagementObjectSearcher(ManagementScope, ObjectQuery)

Source:
ManagementObjectSearcher.cs
Source:
ManagementObjectSearcher.cs
Source:
ManagementObjectSearcher.cs
Source:
ManagementObjectSearcher.cs

Initializes a new instance of the ManagementObjectSearcher class used to invoke the specified query in the specified scope.

public:
 ManagementObjectSearcher(System::Management::ManagementScope ^ scope, System::Management::ObjectQuery ^ query);
public ManagementObjectSearcher (System.Management.ManagementScope scope, System.Management.ObjectQuery query);
new System.Management.ManagementObjectSearcher : System.Management.ManagementScope * System.Management.ObjectQuery -> System.Management.ManagementObjectSearcher
Public Sub New (scope As ManagementScope, query As ObjectQuery)

Parameters

scope
ManagementScope

A ManagementScope representing the scope in which to invoke the query.

query
ObjectQuery

An ObjectQuery representing the query to be invoked.

Examples

The following example initializes a new instance of the ManagementObjectSearcher class with a specific query and scope.

using System;
using System.Management;

public class Sample
{
    public static void Main(string[] args)
    {
        ManagementScope myScope =
            new ManagementScope("root\\CIMV2");
        SelectQuery q =
            new SelectQuery("Win32_LogicalDisk");
        ManagementObjectSearcher s =
            new ManagementObjectSearcher(myScope,q);

        foreach (ManagementObject disk in s.Get())
        {
            // show the disk instance
            Console.WriteLine(disk.ToString());
        }
    }
}
Imports System.Management


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

        Dim myScope As New ManagementScope("root\CIMV2")
        Dim q As New SelectQuery("Win32_LogicalDisk")
        Dim s As New ManagementObjectSearcher(myScope, q)

        For Each disk As ManagementObject In s.Get()
            'show the disk instance
            Console.WriteLine(disk.ToString())
        Next


    End Function 'Main
End Class

Remarks

If no scope is specified, the default scope (DefaultPath) is used.

.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

ManagementObjectSearcher(String, String)

Source:
ManagementObjectSearcher.cs
Source:
ManagementObjectSearcher.cs
Source:
ManagementObjectSearcher.cs
Source:
ManagementObjectSearcher.cs

Initializes a new instance of the ManagementObjectSearcher class used to invoke the specified query in the specified scope.

public:
 ManagementObjectSearcher(System::String ^ scope, System::String ^ queryString);
public ManagementObjectSearcher (string scope, string queryString);
new System.Management.ManagementObjectSearcher : string * string -> System.Management.ManagementObjectSearcher
Public Sub New (scope As String, queryString As String)

Parameters

scope
String

The scope in which to query.

queryString
String

The query to be invoked.

Examples

The following example initializes a new instance of the ManagementObjectSearcher class with a specific query and scope.

using System;
using System.Management;

public class Sample
{
    public static void Main(string[] args)
    {
        ManagementObjectSearcher s =
            new ManagementObjectSearcher(
            "root\\CIMV2",
            "SELECT * FROM Win32_Service" +
            " WHERE State='Running'");

        foreach (ManagementObject service in s.Get())
        {
            // show the instance
            Console.WriteLine(service.ToString());
        }
    }
}
Imports System.Management


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

        Dim s As New ManagementObjectSearcher( _
            "root\CIMV2", _
        "SELECT * FROM Win32_Service WHERE State='Running'")

        For Each service As ManagementObject In s.Get()
            'show the instance
            Console.WriteLine(service.ToString())
        Next


    End Function 'Main
End Class

Remarks

If no scope is specified, the default scope (DefaultPath) is used.

.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

ManagementObjectSearcher(ManagementScope, ObjectQuery, EnumerationOptions)

Source:
ManagementObjectSearcher.cs
Source:
ManagementObjectSearcher.cs
Source:
ManagementObjectSearcher.cs
Source:
ManagementObjectSearcher.cs

Initializes a new instance of the ManagementObjectSearcher class to be used to invoke the specified query in the specified scope, with the specified options.

public:
 ManagementObjectSearcher(System::Management::ManagementScope ^ scope, System::Management::ObjectQuery ^ query, System::Management::EnumerationOptions ^ options);
public ManagementObjectSearcher (System.Management.ManagementScope scope, System.Management.ObjectQuery query, System.Management.EnumerationOptions options);
new System.Management.ManagementObjectSearcher : System.Management.ManagementScope * System.Management.ObjectQuery * System.Management.EnumerationOptions -> System.Management.ManagementObjectSearcher
Public Sub New (scope As ManagementScope, query As ObjectQuery, options As EnumerationOptions)

Parameters

scope
ManagementScope

A ManagementScope specifying the scope of the query.

query
ObjectQuery

An ObjectQuery specifying the query to be invoked.

options
EnumerationOptions

An EnumerationOptions specifying additional options to be used for the query.

Examples

The following example initializes a new instance of the ManagementObjectSearcher class with a specific query, scope, and enumeration options.

using System;
using System.Management;

public class Sample
{
    public static void Main(string[] args)
    {
        ManagementScope scope =
            new ManagementScope("root\\CIMV2");
        SelectQuery q =
            new SelectQuery("SELECT * FROM Win32_LogicalDisk");
        EnumerationOptions o =
            new EnumerationOptions(
            null, System.TimeSpan.MaxValue,
            1, true, false, true,
            true, false, true, true);
        ManagementObjectSearcher s =
            new ManagementObjectSearcher(scope, q, o);

        foreach (ManagementObject disk in s.Get())
        {
            // show the disk instance
            Console.WriteLine(disk.ToString());
        }
    }
}
Imports System.Management


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

        Dim scope As New ManagementScope("root\MyApp")
        Dim q As New SelectQuery("SELECT * FROM Win32_LogicalDisk")
        Dim o As New EnumerationOptions( _
            Nothing, System.TimeSpan.MaxValue, 1, _
            True, False, True, True, False, _
            True, True)
        Dim s As New ManagementObjectSearcher(scope, q, o)

        For Each disk As ManagementObject In s.Get()
            'show the disk instance
            Console.WriteLine(disk.ToString())
        Next


    End Function 'Main
End Class

Remarks

.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

ManagementObjectSearcher(String, String, EnumerationOptions)

Source:
ManagementObjectSearcher.cs
Source:
ManagementObjectSearcher.cs
Source:
ManagementObjectSearcher.cs
Source:
ManagementObjectSearcher.cs

Initializes a new instance of the ManagementObjectSearcher class used to invoke the specified query, in the specified scope, and with the specified options.

public:
 ManagementObjectSearcher(System::String ^ scope, System::String ^ queryString, System::Management::EnumerationOptions ^ options);
public ManagementObjectSearcher (string scope, string queryString, System.Management.EnumerationOptions options);
new System.Management.ManagementObjectSearcher : string * string * System.Management.EnumerationOptions -> System.Management.ManagementObjectSearcher
Public Sub New (scope As String, queryString As String, options As EnumerationOptions)

Parameters

scope
String

The scope in which the query should be invoked.

queryString
String

The query to be invoked.

options
EnumerationOptions

An EnumerationOptions specifying additional options for the query.

Examples

The following example initializes a new instance of the ManagementObjectSearcher class with a specific query, scope, and enumeration options.

using System;
using System.Management;

public class Sample
{
    public static void Main(string[] args)
    {
        ManagementObjectSearcher s =
            new ManagementObjectSearcher(
            "root\\CIMV2",
            "SELECT * FROM Win32_Service",
            new EnumerationOptions(
            null, System.TimeSpan.MaxValue,
            1, true, false, true,
            true, false, true, true));

        foreach (ManagementObject service in s.Get())
        {
            // show the service
            Console.WriteLine(service.ToString());
        }
    }
}
Imports System.Management


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

        Dim s As New ManagementObjectSearcher( _
            "root\MyApp", _
            "SELECT * FROM Win32_Service", _
            New EnumerationOptions( _
            Nothing, System.TimeSpan.MaxValue, 1, _
            True, False, True, True, False, _
            True, True))


        For Each service As ManagementObject In s.Get()
            'show the instance
            Console.WriteLine(service.ToString())
        Next


    End Function 'Main
End Class

Remarks

.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