ManagementClass 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 ManagementClass 類別的新執行個體。
多載
| 名稱 | Description |
|---|---|
| ManagementClass() |
初始化 ManagementClass 類別的新執行個體。 這就是無參數建構子。 |
| ManagementClass(ManagementPath) |
初始化 ManagementClass 類別的新執行個體。 該類別代表來自 WMI 的通用資訊模型(CIM)管理類別,如 Win32_LogicalDisk,可代表磁碟機,以及 Win32_Process,代表程序,如 Notepad.exe。 |
| ManagementClass(String) |
初始化一個初始化到指定路徑的類別新實例 ManagementClass 。 該類別代表來自 WMI 的通用資訊模型(CIM)管理類別,如 Win32_LogicalDisk,可代表磁碟機,以及 Win32_Process,代表程序,如 Notepad.exe。 |
| ManagementClass(ManagementPath, ObjectGetOptions) |
使用指定的選項初始化該類別的新實例 ManagementClass ,初始化為指定 WMI 類別路徑。 該類別代表來自 WMI 的通用資訊模型(CIM)管理類別,如 Win32_LogicalDisk,可代表磁碟機,以及 Win32_Process,代表程序,如 Notepad.exe。 |
| ManagementClass(SerializationInfo, StreamingContext) |
已淘汰.
從指定的 和 ManagementClass 類別實例SerializationInfo中初始化該StreamingContext類別的新實例。 |
| ManagementClass(String, ObjectGetOptions) |
使用指定的選項初始化該類別的新實例 ManagementClass ,初始化為指定 WMI 類別路徑。 該類別代表來自 WMI 的通用資訊模型(CIM)管理類別,如 Win32_LogicalDisk,可代表磁碟機,以及 Win32_Process,代表程序,如 Notepad.exe。 |
| ManagementClass(ManagementScope, ManagementPath, ObjectGetOptions) |
初始化該類別的新實例 ManagementClass ,針對指定的 WMI 類別,在指定的作用域內並使用指定的選項。 該類別代表來自 WMI 的通用資訊模型(CIM)管理類別,如 Win32_LogicalDisk,可代表磁碟機,以及 Win32_Process,代表程序,如 Notepad.exe。 |
| ManagementClass(String, String, ObjectGetOptions) |
初始化該類別的新實例 ManagementClass ,針對指定的 WMI 類別,在指定的範圍內,並以指定的選項進行。 該類別代表來自 WMI 的通用資訊模型(CIM)管理類別,如 Win32_LogicalDisk,可代表磁碟機,以及 Win32_Process,代表程序,如 Notepad.exe。 |
備註
.NET Framework 安全性
完全信任當下的來電者。 此成員無法被部分受信任的程式碼使用。 欲了解更多資訊,請參閱 「部分受信任程式碼的函式庫使用」。
ManagementClass()
初始化 ManagementClass 類別的新執行個體。 這就是無參數建構子。
public:
ManagementClass();
public ManagementClass();
Public Sub New ()
範例
以下範例說明如何使用無參數建構子初始化變 ManagementClass 數 ManagementClass 。 範例列出了所建立類別的方法、屬性與限定符。
using System;
using System.Management;
public class Sample
{
public static void Main()
{
// Get the WMI class
ManagementClass processClass =
new ManagementClass();
processClass.Path = new
ManagementPath("Win32_Process");
// Get the methods in the class
MethodDataCollection methods =
processClass.Methods;
// display the methods
Console.WriteLine("Method Names: ");
foreach (MethodData method in methods)
{
Console.WriteLine(method.Name);
}
Console.WriteLine();
// Get the properties in the class
PropertyDataCollection properties =
processClass.Properties;
// display the properties
Console.WriteLine("Property Names: ");
foreach (PropertyData property in properties)
{
Console.WriteLine(property.Name);
}
Console.WriteLine();
// Get the Qualifiers in the class
QualifierDataCollection qualifiers =
processClass.Qualifiers;
// display the qualifiers
Console.WriteLine("Qualifier Names: ");
foreach (QualifierData qualifier in qualifiers)
{
Console.WriteLine(qualifier.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
processClass.Path = New _
ManagementPath("Win32_Process")
' Get the methods in the class
Dim methods As MethodDataCollection
methods = processClass.Methods
' display the methods
Console.WriteLine("Method Names: ")
For Each method As MethodData In methods
Console.WriteLine(method.Name)
Next
Console.WriteLine()
' Get the properties in the class
Dim properties As PropertyDataCollection
properties = processClass.Properties
' display the properties
Console.WriteLine("Property Names: ")
For Each p As PropertyData In properties
Console.WriteLine(p.Name)
Next
Console.WriteLine()
' Get the Qualifiers in the class
Dim qualifiers As QualifierDataCollection = _
processClass.Qualifiers()
' display the qualifiers
Console.WriteLine("Qualifier Names: ")
For Each qualifier As QualifierData In qualifiers
Console.WriteLine(qualifier.Name)
Next
End Function
End Class
備註
.NET Framework 安全性
完全信任當下的來電者。 此成員無法被部分受信任的程式碼使用。 欲了解更多資訊,請參閱 「部分受信任程式碼的函式庫使用」。
適用於
ManagementClass(ManagementPath)
初始化 ManagementClass 類別的新執行個體。 該類別代表來自 WMI 的通用資訊模型(CIM)管理類別,如 Win32_LogicalDisk,可代表磁碟機,以及 Win32_Process,代表程序,如 Notepad.exe。
public:
ManagementClass(System::Management::ManagementPath ^ path);
public ManagementClass(System.Management.ManagementPath path);
new System.Management.ManagementClass : System.Management.ManagementPath -> System.Management.ManagementClass
Public Sub New (path As ManagementPath)
參數
- path
- ManagementPath
A ManagementPath 指定要綁定的 WMI 類別。 參數必須指定一個 WMI 類別路徑。 該班代表WMI的CIM管理班級。 CIM 類別代表管理資訊,包括硬體、軟體、流程等。 欲了解更多Windows CIM 課程資訊,請參閱 CIM 課程。
範例
以下範例說明如何用ManagementClass建構子初始化變ManagementClass數。 範例列出了所建立類別的方法、屬性與限定符。
using System;
using System.Management;
public class Sample
{
public static void Main()
{
// Get the WMI class
ManagementClass c = new ManagementClass(
new ManagementPath("Win32_LogicalDisk"));
// Get the methods in the class
MethodDataCollection methods =
c.Methods;
// display the methods
Console.WriteLine("Method Names: ");
foreach (MethodData method in methods)
{
Console.WriteLine(method.Name);
}
Console.WriteLine();
// Get the properties in the class
PropertyDataCollection properties =
c.Properties;
// display the properties
Console.WriteLine("Property Names: ");
foreach (PropertyData property in properties)
{
Console.WriteLine(property.Name);
}
Console.WriteLine();
// Get the Qualifiers in the class
QualifierDataCollection qualifiers =
c.Qualifiers;
// display the qualifiers
Console.WriteLine("Qualifier Names: ");
foreach (QualifierData qualifier in qualifiers)
{
Console.WriteLine(qualifier.Name);
}
}
}
Imports System.Management
Class Sample
Public Overloads Shared Function _
Main(ByVal args() As String) As Integer
' Get the WMI class
Dim c As New ManagementClass( _
New ManagementPath("Win32_LogicalDisk"))
' Get the methods in the class
Dim methods As MethodDataCollection
methods = c.Methods
' display the methods
Console.WriteLine("Method Names: ")
For Each method As MethodData In methods
Console.WriteLine(method.Name)
Next
Console.WriteLine()
' Get the properties in the class
Dim properties As PropertyDataCollection
properties = c.Properties
' display the properties
Console.WriteLine("Property Names: ")
For Each p As PropertyData In properties
Console.WriteLine(p.Name)
Next
Console.WriteLine()
' Get the Qualifiers in the class
Dim qualifiers As QualifierDataCollection = _
c.Qualifiers()
' display the qualifiers
Console.WriteLine("Qualifier Names: ")
For Each qualifier As QualifierData In qualifiers
Console.WriteLine(qualifier.Name)
Next
End Function
End Class
備註
參數 path 必須指定一個 WMI 類別路徑。
.NET Framework 安全性
完全信任當下的來電者。 此成員無法被部分受信任的程式碼使用。 欲了解更多資訊,請參閱 「部分受信任程式碼的函式庫使用」。
適用於
ManagementClass(String)
初始化一個初始化到指定路徑的類別新實例 ManagementClass 。 該類別代表來自 WMI 的通用資訊模型(CIM)管理類別,如 Win32_LogicalDisk,可代表磁碟機,以及 Win32_Process,代表程序,如 Notepad.exe。
public:
ManagementClass(System::String ^ path);
public ManagementClass(string path);
new System.Management.ManagementClass : string -> System.Management.ManagementClass
Public Sub New (path As String)
參數
- path
- String
通往 WMI 課程的道路。 該班代表WMI的CIM管理班級。 CIM 類別代表管理資訊,包括硬體、軟體、流程等。 欲了解更多Windows CIM 課程資訊,請參閱 CIM 課程。
範例
以下範例說明如何用ManagementClass建構子初始ManagementClass化變數。 範例列出了所建立類別的方法、屬性與限定符。
using System;
using System.Management;
public class Sample
{
public static void Main()
{
// Get the WMI class
ManagementClass c =
new ManagementClass("Win32_LogicalDisk");
// Get the methods in the class
MethodDataCollection methods =
c.Methods;
// display the methods
Console.WriteLine("Method Names: ");
foreach (MethodData method in methods)
{
Console.WriteLine(method.Name);
}
Console.WriteLine();
// Get the properties in the class
PropertyDataCollection properties =
c.Properties;
// display the properties
Console.WriteLine("Property Names: ");
foreach (PropertyData property in properties)
{
Console.WriteLine(property.Name);
}
Console.WriteLine();
// Get the Qualifiers in the class
QualifierDataCollection qualifiers =
c.Qualifiers;
// display the qualifiers
Console.WriteLine("Qualifier Names: ");
foreach (QualifierData qualifier in qualifiers)
{
Console.WriteLine(qualifier.Name);
}
}
}
Imports System.Management
Class Sample
Public Overloads Shared Function _
Main(ByVal args() As String) As Integer
' Get the WMI class
Dim c As New ManagementClass("Win32_LogicalDisk")
' Get the methods in the class
Dim methods As MethodDataCollection
methods = c.Methods
' display the methods
Console.WriteLine("Method Names: ")
For Each method As MethodData In methods
Console.WriteLine(method.Name)
Next
Console.WriteLine()
' Get the properties in the class
Dim properties As PropertyDataCollection
properties = c.Properties
' display the properties
Console.WriteLine("Property Names: ")
For Each p As PropertyData In properties
Console.WriteLine(p.Name)
Next
Console.WriteLine()
' Get the Qualifiers in the class
Dim qualifiers As QualifierDataCollection = _
c.Qualifiers()
' display the qualifiers
Console.WriteLine("Qualifier Names: ")
For Each qualifier As QualifierData In qualifiers
Console.WriteLine(qualifier.Name)
Next
End Function
End Class
備註
.NET Framework 安全性
完全信任當下的來電者。 此成員無法被部分受信任的程式碼使用。 欲了解更多資訊,請參閱 「部分受信任程式碼的函式庫使用」。
適用於
ManagementClass(ManagementPath, ObjectGetOptions)
使用指定的選項初始化該類別的新實例 ManagementClass ,初始化為指定 WMI 類別路徑。 該類別代表來自 WMI 的通用資訊模型(CIM)管理類別,如 Win32_LogicalDisk,可代表磁碟機,以及 Win32_Process,代表程序,如 Notepad.exe。
public:
ManagementClass(System::Management::ManagementPath ^ path, System::Management::ObjectGetOptions ^ options);
public ManagementClass(System.Management.ManagementPath path, System.Management.ObjectGetOptions options);
new System.Management.ManagementClass : System.Management.ManagementPath * System.Management.ObjectGetOptions -> System.Management.ManagementClass
Public Sub New (path As ManagementPath, options As ObjectGetOptions)
參數
- path
- ManagementPath
一個 ManagementPath 代表 WMI 類別路徑的實例。 該班代表WMI的CIM管理班級。 CIM 類別代表管理資訊,包括硬體、軟體、流程等。 欲了解更多Windows CIM 課程資訊,請參閱 CIM 課程。
- options
- ObjectGetOptions
A ObjectGetOptions 表示取回此類別時可使用的選項。
範例
以下範例說明如何用ManagementClass建構子初始化變ManagementClass數。 範例列出了所建立類別的方法、屬性和限定符(包括修正後的限定符)。
using System;
using System.Management;
public class Sample
{
public static void Main()
{
// Get the WMI class
ManagementPath p =
new ManagementPath("Win32_Process");
// Options specify that amended qualifiers
// are to be retrieved along with the class
ObjectGetOptions o = new ObjectGetOptions(
null, System.TimeSpan.MaxValue, true);
ManagementClass c = new ManagementClass(p,o);
// Get the methods in the class
MethodDataCollection methods =
c.Methods;
// display the methods
Console.WriteLine("Method Names: ");
foreach (MethodData method in methods)
{
Console.WriteLine(method.Name);
}
Console.WriteLine();
// Get the properties in the class
PropertyDataCollection properties =
c.Properties;
// display the properties
Console.WriteLine("Property Names: ");
foreach (PropertyData property in properties)
{
Console.WriteLine(property.Name);
}
Console.WriteLine();
// Get the Qualifiers in the class
QualifierDataCollection qualifiers =
c.Qualifiers;
// display the qualifiers
Console.WriteLine("Qualifier Names: ");
foreach (QualifierData qualifier in qualifiers)
{
Console.WriteLine(qualifier.Name);
}
}
}
Imports System.Management
Class Sample
Public Overloads Shared Function _
Main(ByVal args() As String) As Integer
' Get the WMI class
Dim p As New ManagementPath("Win32_Process")
' Options specify that amended qualifiers
' are to be retrieved along with the class
Dim o As New ObjectGetOptions( _
Nothing, System.TimeSpan.MaxValue, True)
Dim c As New ManagementClass(p, o)
' Get the methods in the class
Dim methods As MethodDataCollection
methods = c.Methods
' display the methods
Console.WriteLine("Method Names: ")
For Each method As MethodData In methods
Console.WriteLine(method.Name)
Next
Console.WriteLine()
' Get the properties in the class
Dim properties As PropertyDataCollection
properties = c.Properties
' display the properties
Console.WriteLine("Property Names: ")
For Each pdata As PropertyData In properties
Console.WriteLine(pdata.Name)
Next
Console.WriteLine()
' Get the Qualifiers in the class
Dim qualifiers As QualifierDataCollection = _
c.Qualifiers()
' display the qualifiers
Console.WriteLine("Qualifier Names: ")
For Each qualifier As QualifierData In qualifiers
Console.WriteLine(qualifier.Name)
Next
End Function
End Class
備註
.NET Framework 安全性
完全信任當下的來電者。 此成員無法被部分受信任的程式碼使用。 欲了解更多資訊,請參閱 「部分受信任程式碼的函式庫使用」。
適用於
ManagementClass(SerializationInfo, StreamingContext)
警告
This API supports obsolete formatter-based serialization. It should not be called or extended by application code.
從指定的 和 ManagementClass 類別實例SerializationInfo中初始化該StreamingContext類別的新實例。
protected:
ManagementClass(System::Runtime::Serialization::SerializationInfo ^ info, System::Runtime::Serialization::StreamingContext context);
[System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
protected ManagementClass(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
protected ManagementClass(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
[<System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
new System.Management.ManagementClass : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Management.ManagementClass
new System.Management.ManagementClass : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Management.ManagementClass
Protected Sub New (info As SerializationInfo, context As StreamingContext)
參數
- info
- SerializationInfo
類別的 SerializationInfo 實例,包含序列化新 ManagementClass的資訊。
- context
- StreamingContext
包含與新序列StreamingContext化串流相關聯來源的類別實例ManagementClass。
- 屬性
備註
.NET Framework 安全性
完全信任當下的來電者。 此成員無法被部分受信任的程式碼使用。 欲了解更多資訊,請參閱 「部分受信任程式碼的函式庫使用」。
適用於
ManagementClass(String, ObjectGetOptions)
使用指定的選項初始化該類別的新實例 ManagementClass ,初始化為指定 WMI 類別路徑。 該類別代表來自 WMI 的通用資訊模型(CIM)管理類別,如 Win32_LogicalDisk,可代表磁碟機,以及 Win32_Process,代表程序,如 Notepad.exe。
public:
ManagementClass(System::String ^ path, System::Management::ObjectGetOptions ^ options);
public ManagementClass(string path, System.Management.ObjectGetOptions options);
new System.Management.ManagementClass : string * System.Management.ObjectGetOptions -> System.Management.ManagementClass
Public Sub New (path As String, options As ObjectGetOptions)
參數
- path
- String
通往 WMI 課程的道路。 該班代表WMI的CIM管理班級。 CIM 類別代表管理資訊,包括硬體、軟體、流程等。 欲了解更多Windows CIM 課程資訊,請參閱 CIM 課程。
- options
- ObjectGetOptions
A ObjectGetOptions 表示取回 WMI 類別時可用的選項。
範例
以下範例說明如何用ManagementClass建構子初始ManagementClass化變數。 範例列出了所建立類別的方法、屬性和限定符(包括修正後的限定符)。
using System;
using System.Management;
public class Sample
{
public static void Main()
{
// Get the WMI class
//Options specify that amended qualifiers
// should be retrieved along with the class
ObjectGetOptions o = new ObjectGetOptions(
null, System.TimeSpan.MaxValue, true);
ManagementClass c =
new ManagementClass("Win32_ComputerSystem",o);
// Get the methods in the class
MethodDataCollection methods =
c.Methods;
// display the methods
Console.WriteLine("Method Names: ");
foreach (MethodData method in methods)
{
Console.WriteLine(method.Name);
}
Console.WriteLine();
// Get the properties in the class
PropertyDataCollection properties =
c.Properties;
// display the properties
Console.WriteLine("Property Names: ");
foreach (PropertyData property in properties)
{
Console.WriteLine(property.Name);
}
Console.WriteLine();
// Get the Qualifiers in the class
QualifierDataCollection qualifiers =
c.Qualifiers;
// display the qualifiers
Console.WriteLine("Qualifier Names: ");
foreach (QualifierData qualifier in qualifiers)
{
Console.WriteLine(qualifier.Name);
}
}
}
Imports System.Management
Class Sample
Public Overloads Shared Function _
Main(ByVal args() As String) As Integer
' Get the WMI class
' Options specify that amended qualifiers
' should be retrieved along with the class
Dim o As New ObjectGetOptions( _
Nothing, System.TimeSpan.MaxValue, True)
Dim c As New ManagementClass("Win32_ComputerSystem", o)
' Get the methods in the class
Dim methods As MethodDataCollection
methods = c.Methods
' display the methods
Console.WriteLine("Method Names: ")
For Each method As MethodData In methods
Console.WriteLine(method.Name)
Next
Console.WriteLine()
' Get the properties in the class
Dim properties As PropertyDataCollection
properties = c.Properties
' display the properties
Console.WriteLine("Property Names: ")
For Each p As PropertyData In properties
Console.WriteLine(p.Name)
Next
Console.WriteLine()
' Get the Qualifiers in the class
Dim qualifiers As QualifierDataCollection = _
c.Qualifiers()
' display the qualifiers
Console.WriteLine("Qualifier Names: ")
For Each qualifier As QualifierData In qualifiers
Console.WriteLine(qualifier.Name)
Next
End Function
End Class
備註
.NET Framework 安全性
完全信任當下的來電者。 此成員無法被部分受信任的程式碼使用。 欲了解更多資訊,請參閱 「部分受信任程式碼的函式庫使用」。
適用於
ManagementClass(ManagementScope, ManagementPath, ObjectGetOptions)
初始化該類別的新實例 ManagementClass ,針對指定的 WMI 類別,在指定的作用域內並使用指定的選項。 該類別代表來自 WMI 的通用資訊模型(CIM)管理類別,如 Win32_LogicalDisk,可代表磁碟機,以及 Win32_Process,代表程序,如 Notepad.exe。
public:
ManagementClass(System::Management::ManagementScope ^ scope, System::Management::ManagementPath ^ path, System::Management::ObjectGetOptions ^ options);
public ManagementClass(System.Management.ManagementScope scope, System.Management.ManagementPath path, System.Management.ObjectGetOptions options);
new System.Management.ManagementClass : System.Management.ManagementScope * System.Management.ManagementPath * System.Management.ObjectGetOptions -> System.Management.ManagementClass
Public Sub New (scope As ManagementScope, path As ManagementPath, options As ObjectGetOptions)
參數
- scope
- ManagementScope
A ManagementScope 用來指定 WMI 類別所在的範圍(伺服器和命名空間)。
- path
- ManagementPath
A ManagementPath 代表指定範圍內 WMI 類別的路徑。 該班代表WMI的CIM管理班級。 CIM 類別代表管理資訊,包括硬體、軟體、流程等。 欲了解更多Windows CIM 課程資訊,請參閱 CIM 課程。
- options
- ObjectGetOptions
還有 ObjectGetOptions 一個指定取回 WMI 類別時可使用的選項。
範例
以下範例說明如何用ManagementClass建構子初始化變ManagementClass數。 範例列出了所建立類別的方法、屬性和限定符(包括修正後的限定符)。 你必須在程式碼中更改範疇(命名空間),才能讓範例在你的電腦上正確執行。
using System;
using System.Management;
public class Sample
{
public static void Main()
{
// Get the WMI class
ManagementScope s =
new ManagementScope("\\\\MyBox\\root\\cimv2");
ManagementPath p = new ManagementPath("Win32_Environment");
ObjectGetOptions o = new ObjectGetOptions(
null, System.TimeSpan.MaxValue, true);
ManagementClass c = new ManagementClass(s, p, o);
// Get the methods in the class
MethodDataCollection methods =
c.Methods;
// display the methods
Console.WriteLine("Method Names: ");
foreach (MethodData method in methods)
{
Console.WriteLine(method.Name);
}
Console.WriteLine();
// Get the properties in the class
PropertyDataCollection properties =
c.Properties;
// display the properties
Console.WriteLine("Property Names: ");
foreach (PropertyData property in properties)
{
Console.WriteLine(property.Name);
}
Console.WriteLine();
// Get the Qualifiers in the class
QualifierDataCollection qualifiers =
c.Qualifiers;
// display the qualifiers
Console.WriteLine("Qualifier Names: ");
foreach (QualifierData qualifier in qualifiers)
{
Console.WriteLine(qualifier.Name);
}
}
}
Imports System.Management
Class Sample
Public Overloads Shared Function _
Main(ByVal args() As String) As Integer
' Get the WMI class
Dim s As New ManagementScope("\\MyBox\root\cimv2")
Dim p As New ManagementPath("Win32_Environment")
Dim o As New ObjectGetOptions( _
Nothing, System.TimeSpan.MaxValue, True)
Dim c As New ManagementClass(s, p, o)
' Get the methods in the class
Dim methods As MethodDataCollection
methods = c.Methods
' display the methods
Console.WriteLine("Method Names: ")
For Each method As MethodData In methods
Console.WriteLine(method.Name)
Next
Console.WriteLine()
' Get the properties in the class
Dim properties As PropertyDataCollection
properties = c.Properties
' display the properties
Console.WriteLine("Property Names: ")
Dim data As PropertyData
For Each data In properties
Console.WriteLine(data.Name)
Next
Console.WriteLine()
' Get the Qualifiers in the class
Dim qualifiers As QualifierDataCollection = _
c.Qualifiers()
' display the qualifiers
Console.WriteLine("Qualifier Names: ")
For Each qualifier As QualifierData In qualifiers
Console.WriteLine(qualifier.Name)
Next
End Function
End Class
備註
路徑可指定為完整路徑(包含伺服器與命名空間)。 然而,若指定示波器,則會覆蓋完整路徑的第一部分。
.NET Framework 安全性
完全信任當下的來電者。 此成員無法被部分受信任的程式碼使用。 欲了解更多資訊,請參閱 「部分受信任程式碼的函式庫使用」。
適用於
ManagementClass(String, String, ObjectGetOptions)
初始化該類別的新實例 ManagementClass ,針對指定的 WMI 類別,在指定的範圍內,並以指定的選項進行。 該類別代表來自 WMI 的通用資訊模型(CIM)管理類別,如 Win32_LogicalDisk,可代表磁碟機,以及 Win32_Process,代表程序,如 Notepad.exe。
public:
ManagementClass(System::String ^ scope, System::String ^ path, System::Management::ObjectGetOptions ^ options);
public ManagementClass(string scope, string path, System.Management.ObjectGetOptions options);
new System.Management.ManagementClass : string * string * System.Management.ObjectGetOptions -> System.Management.ManagementClass
Public Sub New (scope As String, path As String, options As ObjectGetOptions)
參數
- scope
- String
WMI 級別所處的範圍。
- path
- String
在指定範圍內,前往 WMI 類別的路徑。 該班代表WMI的CIM管理班級。 CIM 類別代表管理資訊,包括硬體、軟體、流程等。 欲了解更多Windows CIM 課程資訊,請參閱 CIM 課程。
- options
- ObjectGetOptions
還有 ObjectGetOptions 一個指定取回 WMI 類別時可使用的選項。
範例
以下範例說明如何用ManagementClass建構子初始ManagementClass化變數。 範例列出了所建立類別的方法、屬性和限定符(包括修正後的限定符)。 你必須在程式碼中更改範疇(命名空間),才能讓範例在你的電腦上正確執行。
using System;
using System.Management;
public class Sample
{
public static void Main()
{
// Get the WMI class
//Options specify that amended qualifiers
// should be retrieved along with the class
ManagementClass c =
new ManagementClass("\\\\MyBox\\root\\cimv2",
"Win32_Environment",
new ObjectGetOptions(
null, System.TimeSpan.MaxValue, true));
// Get the methods in the class
MethodDataCollection methods =
c.Methods;
// display the methods
Console.WriteLine("Method Names: ");
foreach (MethodData method in methods)
{
Console.WriteLine(method.Name);
}
Console.WriteLine();
// Get the properties in the class
PropertyDataCollection properties =
c.Properties;
// display the properties
Console.WriteLine("Property Names: ");
foreach (PropertyData property in properties)
{
Console.WriteLine(property.Name);
}
Console.WriteLine();
// Get the Qualifiers in the class
QualifierDataCollection qualifiers =
c.Qualifiers;
// display the qualifiers
Console.WriteLine("Qualifier Names: ");
foreach (QualifierData qualifier in qualifiers)
{
Console.WriteLine(qualifier.Name);
}
}
}
Imports System.Management
Class Sample
Public Overloads Shared Function _
Main(ByVal args() As String) As Integer
' Get the WMI class
' Options specify that amended qualifiers
' should be retrieved along with the class
Dim c As New ManagementClass("\\MyBox\root\cimv2", _
"Win32_Environment", _
New ObjectGetOptions( _
Nothing, System.TimeSpan.MaxValue, True))
' Get the methods in the class
Dim methods As MethodDataCollection
methods = c.Methods
' display the methods
Console.WriteLine("Method Names: ")
For Each method As MethodData In methods
Console.WriteLine(method.Name)
Next
Console.WriteLine()
' Get the properties in the class
Dim properties As PropertyDataCollection
properties = c.Properties
' display the properties
Console.WriteLine("Property Names: ")
For Each p As PropertyData In properties
Console.WriteLine(p.Name)
Next
Console.WriteLine()
' Get the Qualifiers in the class
Dim qualifiers As QualifierDataCollection = _
c.Qualifiers()
' display the qualifiers
Console.WriteLine("Qualifier Names: ")
For Each qualifier As QualifierData In qualifiers
Console.WriteLine(qualifier.Name)
Next
End Function
End Class
備註
路徑可指定為完整路徑(包含伺服器與命名空間)。 然而,若指定示波器,則會覆蓋完整路徑的第一部分。
.NET Framework 安全性
完全信任當下的來電者。 此成員無法被部分受信任的程式碼使用。 欲了解更多資訊,請參閱 「部分受信任程式碼的函式庫使用」。