SelectQuery Constructors
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Initializes a new instance of the SelectQuery class.
Overloads
SelectQuery() |
Initializes a new instance of the SelectQuery class. This is the parameterless constructor. |
SelectQuery(String) |
Initializes a new instance of the SelectQuery class for the specified query or the specified class name. |
SelectQuery(Boolean, String) |
Initializes a new instance of the SelectQuery class for a schema query, optionally specifying a condition. |
SelectQuery(String, String) |
Initializes a new instance of the SelectQuery class with the specified class name and condition. |
SelectQuery(String, String, String[]) |
Initializes a new instance of the SelectQuery class with the specified class name and condition, selecting only the specified properties. |
SelectQuery()
- Source:
- ManagementQuery.cs
- Source:
- ManagementQuery.cs
Initializes a new instance of the SelectQuery class. This is the parameterless constructor.
public:
SelectQuery();
public SelectQuery ();
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
SelectQuery(String)
- Source:
- ManagementQuery.cs
- Source:
- ManagementQuery.cs
Initializes a new instance of the SelectQuery class for the specified query or the specified class name.
public:
SelectQuery(System::String ^ queryOrClassName);
public SelectQuery (string queryOrClassName);
new System.Management.SelectQuery : string -> System.Management.SelectQuery
Public Sub New (queryOrClassName As String)
Parameters
- queryOrClassName
- String
The entire query or the class name to use in the query. The parser in this class attempts to parse the string as a valid WQL SELECT query. If the parser is unsuccessful, it assumes the string is a class name.
Examples
The following example initializes a SelectQuery by specifying a query.
using System;
using System.Management;
class Sample
{
public static void Main(string[] args)
{
SelectQuery sQuery =
new SelectQuery(
"SELECT * FROM Win32_Service WHERE State='Stopped'");
// or
// This is equivalent to "SELECT * FROM Win32_Service"
SelectQuery query = new SelectQuery("Win32_Service");
}
}
Imports System.Management
Public Class Sample
Public Overloads Shared Function _
Main(ByVal args() As String) As Integer
Dim sQuery As New SelectQuery( _
"SELECT * FROM Win32_Service WHERE State='Stopped'")
'or
'This is equivalent to "SELECT * FROM Win32_Service"
Dim query As New SelectQuery("Win32_Service")
End Function
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
SelectQuery(Boolean, String)
- Source:
- ManagementQuery.cs
- Source:
- ManagementQuery.cs
Initializes a new instance of the SelectQuery class for a schema query, optionally specifying a condition.
public:
SelectQuery(bool isSchemaQuery, System::String ^ condition);
public SelectQuery (bool isSchemaQuery, string condition);
new System.Management.SelectQuery : bool * string -> System.Management.SelectQuery
Public Sub New (isSchemaQuery As Boolean, condition As String)
Parameters
- isSchemaQuery
- Boolean
true
to indicate that this is a schema query; otherwise, false
. A false
value is invalid in this constructor.
- condition
- String
The condition to be applied to form the result set of classes.
Examples
The following example initializes a SelectQuery by specifying a condition.
using System;
using System.Management;
public class Sample
{
public static void Main(string[] args)
{
SelectQuery s =
new SelectQuery(true,
"__CLASS = 'Win32_Service'");
ManagementObjectSearcher searcher =
new ManagementObjectSearcher(
s);
foreach (ManagementObject service in searcher.Get())
{
// show the class
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 SelectQuery( _
True, "__CLASS = ""Win32_Service""")
Dim searcher As ManagementObjectSearcher
searcher = New ManagementObjectSearcher(s)
For Each service As ManagementObject In searcher.Get()
'show the class
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
SelectQuery(String, String)
- Source:
- ManagementQuery.cs
- Source:
- ManagementQuery.cs
Initializes a new instance of the SelectQuery class with the specified class name and condition.
public:
SelectQuery(System::String ^ className, System::String ^ condition);
public SelectQuery (string className, string condition);
new System.Management.SelectQuery : string * string -> System.Management.SelectQuery
Public Sub New (className As String, condition As String)
Parameters
- className
- String
The name of the class to select in the query.
- condition
- String
The condition to be applied in the query.
Examples
The following example initializes a SelectQuery by specifying a WMI class name and a condition.
using System;
using System.Management;
public class Sample
{
public static void Main(string[] args)
{
SelectQuery s =
new SelectQuery("Win32_Service",
"State = 'Stopped'");
ManagementObjectSearcher searcher =
new ManagementObjectSearcher(
s);
foreach (ManagementObject service in searcher.Get())
{
// show the class
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 SelectQuery("Win32_Service", _
"State = 'Stopped'")
Dim searcher As ManagementObjectSearcher
searcher = New ManagementObjectSearcher(s)
For Each service As ManagementObject In searcher.Get()
'show the class
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
SelectQuery(String, String, String[])
- Source:
- ManagementQuery.cs
- Source:
- ManagementQuery.cs
Initializes a new instance of the SelectQuery class with the specified class name and condition, selecting only the specified properties.
public:
SelectQuery(System::String ^ className, System::String ^ condition, cli::array <System::String ^> ^ selectedProperties);
public SelectQuery (string className, string condition, string[] selectedProperties);
new System.Management.SelectQuery : string * string * string[] -> System.Management.SelectQuery
Public Sub New (className As String, condition As String, selectedProperties As String())
Parameters
- className
- String
The name of the class from which to select.
- condition
- String
The condition to be applied to instances of the selected class.
- selectedProperties
- String[]
An array of property names to be returned in the query results.
Examples
The following example initializes a SelectQuery by specifying a WMI class name, condition, and array of properties.
using System;
using System.Management;
public class Sample
{
public static void Main(string[] args)
{
String[] properties =
{"Name", "Handle"};
SelectQuery s = new SelectQuery("Win32_Process",
"Name = 'notepad.exe'",
properties);
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 properties() As String = _
{"Name", "Handle"}
Dim s As New SelectQuery("Win32_Process", _
"Name = 'notepad.exe'", _
properties)
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
.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.