ManagementObject 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 ManagementObject 類別的新執行個體。
多載
| 名稱 | Description |
|---|---|
| ManagementObject() |
初始化 ManagementObject 類別的新執行個體。 這就是無參數建構子。 |
| ManagementObject(ManagementPath) |
初始化該類別的新實例 ManagementObject ,以符合指定的 WMI 物件路徑。 路徑以 ManagementPath. |
| ManagementObject(String) |
初始化該類別的新實例 ManagementObject ,以符合指定的 WMI 物件路徑。 路徑以字串形式提供。 |
| ManagementObject(ManagementPath, ObjectGetOptions) |
初始化綁定於指定 WMI 路徑的新類別實例 ManagementObject ,包含指定的額外選項。 |
| ManagementObject(SerializationInfo, StreamingContext) |
已淘汰.
初始化一個可序列化的新類別實例 ManagementObject 。 |
| ManagementObject(String, ObjectGetOptions) |
初始化綁定於指定 WMI 路徑的新類別實例 ManagementObject ,包含指定的額外選項。 在此變體中,路徑可指定為字串。 |
| ManagementObject(ManagementScope, ManagementPath, ObjectGetOptions) |
初始化綁定於指定 WMI 路徑且包含指定選項的新類別實例 ManagementObject 。 |
| ManagementObject(String, String, ObjectGetOptions) |
初始化綁定於指定 WMI 路徑的類別新實例 ManagementObject ,並包含指定的選項。 作用域與路徑以字串形式指定。 |
ManagementObject()
初始化 ManagementObject 類別的新執行個體。 這就是無參數建構子。
public:
ManagementObject();
public ManagementObject();
Public Sub New ()
範例
以下範例初始化一個帶有無參數建構子的新 ManagementObject 類別實例。
using System;
using System.Management;
class Sample
{
public static int Main(string[] args)
{
ManagementObject o = new ManagementObject();
// Now set the path on this object to
// bind it to a 'real' manageable entity
o.Path =
new ManagementPath("Win32_LogicalDisk='c:'");
//Now it can be used
Console.WriteLine(o["FreeSpace"]);
return 0;
}
}
Imports System.Management
Class Sample_ManagementClass
Public Overloads Shared Function Main( _
ByVal args() As String) As Integer
Dim o As New ManagementObject
Dim mp As New _
ManagementPath("Win32_LogicalDisk='c:'")
' Now set the path on this object to
' bind it to a 'real' manageable entity
o.Path = mp
'Now it can be used
Console.WriteLine(o("FreeSpace"))
Return 0
End Function
End Class
備註
.NET Framework 安全性
完全信任當下的來電者。 此成員無法被部分受信任的程式碼使用。 欲了解更多資訊,請參閱 「部分受信任程式碼的函式庫使用」。
適用於
ManagementObject(ManagementPath)
初始化該類別的新實例 ManagementObject ,以符合指定的 WMI 物件路徑。 路徑以 ManagementPath.
public:
ManagementObject(System::Management::ManagementPath ^ path);
public ManagementObject(System.Management.ManagementPath path);
new System.Management.ManagementObject : System.Management.ManagementPath -> System.Management.ManagementObject
Public Sub New (path As ManagementPath)
參數
- path
- ManagementPath
ManagementPath A 包含通往 WMI 物件的路徑。
範例
以下範例初始化一個新實例 ManagementObject ,並設定指定的 WMI 物件路徑。
using System;
using System.Management;
class Sample
{
public static int Main(string[] args)
{
ManagementPath p =
new ManagementPath(
"Win32_Service.Name='Alerter'");
ManagementObject o = new ManagementObject(p);
//Now it can be used
Console.WriteLine(o["Name"]);
return 0;
}
}
Imports System.Management
Class Sample_ManagementClass
Public Overloads Shared Function Main( _
ByVal args() As String) As Integer
Dim p As New ManagementPath( _
"Win32_Service.Name=""Alerter""")
Dim o As New ManagementObject(p)
'Now it can be used
Console.WriteLine(o("Name"))
Return 0
End Function
End Class
備註
.NET Framework 安全性
完全信任當下的來電者。 此成員無法被部分受信任的程式碼使用。 欲了解更多資訊,請參閱 「部分受信任程式碼的函式庫使用」。
適用於
ManagementObject(String)
初始化該類別的新實例 ManagementObject ,以符合指定的 WMI 物件路徑。 路徑以字串形式提供。
public:
ManagementObject(System::String ^ path);
public ManagementObject(string path);
new System.Management.ManagementObject : string -> System.Management.ManagementObject
Public Sub New (path As String)
參數
- path
- String
WMI 路徑。
範例
以下範例初始化該 ManagementObject 類別的新實例。
using System;
using System.Management;
class Sample
{
public static int Main(string[] args)
{
ManagementObject o =
new ManagementObject("Win32_Service.Name='Alerter'");
//or with a full path :
ManagementObject mObj =
new ManagementObject(
"\\\\MyServer\\root\\MyApp:MyClass.Key='abc'");
return 0;
}
}
Imports System.Management
Class Sample_ManagementClass
Public Overloads Shared Function Main( _
ByVal args() As String) As Integer
Dim o As New ManagementObject( _
"Win32_Service.Name=""Alerter""")
' or with a full path :
Dim mObj As New ManagementObject( _
"\\\\MyServer\\root\\MyApp:MyClass.Key=""abc""")
Return 0
End Function
End Class
備註
若指定的路徑僅為相對路徑(未指定伺服器或命名空間),預設路徑為本地機器,預設命名空間為 DefaultPath 路徑(預設為 root\cimv2)。 如果使用者指定完整路徑,預設設定會被覆寫。
.NET Framework 安全性
完全信任當下的來電者。 此成員無法被部分受信任的程式碼使用。 欲了解更多資訊,請參閱 「部分受信任程式碼的函式庫使用」。
適用於
ManagementObject(ManagementPath, ObjectGetOptions)
初始化綁定於指定 WMI 路徑的新類別實例 ManagementObject ,包含指定的額外選項。
public:
ManagementObject(System::Management::ManagementPath ^ path, System::Management::ObjectGetOptions ^ options);
public ManagementObject(System.Management.ManagementPath path, System.Management.ObjectGetOptions options);
new System.Management.ManagementObject : System.Management.ManagementPath * System.Management.ObjectGetOptions -> System.Management.ManagementObject
Public Sub New (path As ManagementPath, options As ObjectGetOptions)
參數
- path
- ManagementPath
ManagementPath A 包含 WMI 路徑。
- options
- ObjectGetOptions
包含 ObjectGetOptions 綁定到 WMI 物件的額外選項。 如果要使用預設選項,這個參數可以是空的。
範例
以下範例初始化一個綁定於特定 WMI 路徑的類別新實例 ManagementObject 。
using System;
using System.Management;
class Sample
{
public static int Main(string[] args)
{
ManagementPath p =
new ManagementPath("Win32_Service");
// Set options for no context info
// but requests amended qualifiers
// to be contained in the object
ObjectGetOptions opt =
new ObjectGetOptions(
null, System.TimeSpan.MaxValue, true);
ManagementClass c =
new ManagementClass(p, opt);
Console.WriteLine(
c.Qualifiers["Description"].Value);
return 0;
}
}
Imports System.Management
Class Sample_ManagementClass
Public Overloads Shared Function Main( _
ByVal args() As String) As Integer
Dim p As New ManagementPath("Win32_Service")
' Set options for no context info
' but requests amended qualifiers
' to be contained in the object
Dim opt As New ObjectGetOptions( _
Nothing, TimeSpan.MaxValue, True)
Dim c As New ManagementClass(p, opt)
Console.WriteLine(c.Qualifiers("Description").Value)
Return 0
End Function
End Class
備註
.NET Framework 安全性
完全信任當下的來電者。 此成員無法被部分受信任的程式碼使用。 欲了解更多資訊,請參閱 「部分受信任程式碼的函式庫使用」。
適用於
ManagementObject(SerializationInfo, StreamingContext)
警告
This API supports obsolete formatter-based serialization. It should not be called or extended by application code.
初始化一個可序列化的新類別實例 ManagementObject 。
protected:
ManagementObject(System::Runtime::Serialization::SerializationInfo ^ info, System::Runtime::Serialization::StreamingContext context);
public:
ManagementObject(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 ManagementObject(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
public ManagementObject(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
protected ManagementObject(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.ManagementObject : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Management.ManagementObject
new System.Management.ManagementObject : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Management.ManagementObject
Protected Sub New (info As SerializationInfo, context As StreamingContext)
Public Sub New (info As SerializationInfo, context As StreamingContext)
參數
- info
- SerializationInfo
用 SerializationInfo 資料填充。
- context
- StreamingContext
此序列化的目的地(見 StreamingContext)。
- 屬性
備註
.NET Framework 安全性
完全信任當下的來電者。 此成員無法被部分受信任的程式碼使用。 欲了解更多資訊,請參閱 「部分受信任程式碼的函式庫使用」。
適用於
ManagementObject(String, ObjectGetOptions)
初始化綁定於指定 WMI 路徑的新類別實例 ManagementObject ,包含指定的額外選項。 在此變體中,路徑可指定為字串。
public:
ManagementObject(System::String ^ path, System::Management::ObjectGetOptions ^ options);
public ManagementObject(string path, System.Management.ObjectGetOptions options);
new System.Management.ManagementObject : string * System.Management.ObjectGetOptions -> System.Management.ManagementObject
Public Sub New (path As String, options As ObjectGetOptions)
參數
- path
- String
通往該物件的 WMI 路徑。
- options
- ObjectGetOptions
一個 ObjectGetOptions 代表取得指定 WMI 物件的選項。
範例
以下範例初始化該 ManagementObject 類別的新實例。
using System;
using System.Management;
class Sample
{
public static int Main(string[] args)
{
// Set options for no context info,
// but requests amended qualifiers
// to be contained in the object
ObjectGetOptions opt =
new ObjectGetOptions(null, System.TimeSpan.MaxValue, true);
ManagementObject o =
new ManagementObject(
"Win32_Service", opt);
Console.WriteLine(o.GetQualifierValue("Description"));
return 0;
}
}
Imports System.Management
Class Sample_ManagementClass
Public Overloads Shared Function Main( _
ByVal args() As String) As Integer
' Set options for no context info,
' but requests amended qualifiers
' to be contained in the object
Dim opt As New ObjectGetOptions( _
Nothing, System.TimeSpan.MaxValue, True)
Dim o As New ManagementObject( _
"Win32_Service", opt)
Console.WriteLine(o.GetQualifierValue("Description"))
Return 0
End Function
End Class
備註
.NET Framework 安全性
完全信任當下的來電者。 此成員無法被部分受信任的程式碼使用。 欲了解更多資訊,請參閱 「部分受信任程式碼的函式庫使用」。
適用於
ManagementObject(ManagementScope, ManagementPath, ObjectGetOptions)
初始化綁定於指定 WMI 路徑且包含指定選項的新類別實例 ManagementObject 。
public:
ManagementObject(System::Management::ManagementScope ^ scope, System::Management::ManagementPath ^ path, System::Management::ObjectGetOptions ^ options);
public ManagementObject(System.Management.ManagementScope scope, System.Management.ManagementPath path, System.Management.ObjectGetOptions options);
new System.Management.ManagementObject : System.Management.ManagementScope * System.Management.ManagementPath * System.Management.ObjectGetOptions -> System.Management.ManagementObject
Public Sub New (scope As ManagementScope, path As ManagementPath, options As ObjectGetOptions)
參數
- scope
- ManagementScope
A ManagementScope 代表 WMI 物件所處的範圍。 在此版本中,範圍只能是 WMI 命名空間。
- path
- ManagementPath
A ManagementPath 代表通往可管理物件的 WMI 路徑。
- options
- ObjectGetOptions
還有 ObjectGetOptions 其他取得該物品的具體選項。
範例
以下範例初始化一個綁定於特定 WMI 路徑的類別新實例 ManagementObject 。
using System;
using System.Management;
class Sample
{
public static int Main(string[] args)
{
ManagementScope s = new ManagementScope(
"\\\\MyMachine\\root\\cimv2");
ManagementPath p =
new ManagementPath(
"Win32_Service");
// Set options for no context info,
// but requests amended qualifiers
// to be contained in the object
ObjectGetOptions opt =
new ObjectGetOptions(
null, TimeSpan.MaxValue, true);
ManagementObject o = new ManagementObject(s, p, opt);
Console.WriteLine(o.Qualifiers["Description"].Value);
return 0;
}
}
Imports System.Management
Class Sample_ManagementClass
Public Overloads Shared Function Main( _
ByVal args() As String) As Integer
Dim s As New ManagementScope( _
"\\MyMachine\root\cimv2")
Dim p As New ManagementPath( _
"Win32_Service")
' Set options for no context info,
' but requests amended qualifiers
' to be contained in the object
Dim opt As ObjectGetOptions
opt = New ObjectGetOptions( _
Nothing, TimeSpan.MaxValue, True)
Dim o As ManagementObject
o = New ManagementObject(s, p, opt)
Console.WriteLine(o.Qualifiers("Description").Value)
Return 0
End Function
End Class
備註
由於 WMI 路徑可以是相對的,也可以是完整的,範圍與指定的路徑之間可能會產生衝突。 然而,如果指定一個範圍並指定相對的 WMI 路徑,則不會有衝突。 以下是一些可能的衝突:
若未指定作用域且指定相對 WMI 路徑,則該範圍將預設為本地機器的 DefaultPath。
若未指定範圍,且指定完整 WMI 路徑,則範圍將從完整路徑的範圍部分推斷。 例如,完整的 WMI 路徑: \\MyMachine\root\MyNamespace:MyClass.Name='abc' 將代表 WMI 物件 'MyClass.Name='abc'“,置於作用域 '\\MyMachine\root\MyNamespace' 中。
若指定範圍且指定完整 WMI 路徑,則該範圍會覆蓋完整路徑的範圍部分。 例如,若指定了以下作用域:\\MyMachine\root\MyScope,且完整路徑指定為:\\MyMachine\root\MyNamespace:MyClass.Name='abc',則尋找以下 object: \\MyMachine\root\MyScope:MyClass.Name= 'abc' 內容(忽略完整路徑的範圍部分)。
.NET Framework 安全性
完全信任當下的來電者。 此成員無法被部分受信任的程式碼使用。 欲了解更多資訊,請參閱 「部分受信任程式碼的函式庫使用」。
適用於
ManagementObject(String, String, ObjectGetOptions)
初始化綁定於指定 WMI 路徑的類別新實例 ManagementObject ,並包含指定的選項。 作用域與路徑以字串形式指定。
public:
ManagementObject(System::String ^ scopeString, System::String ^ pathString, System::Management::ObjectGetOptions ^ options);
public ManagementObject(string scopeString, string pathString, System.Management.ObjectGetOptions options);
new System.Management.ManagementObject : string * string * System.Management.ObjectGetOptions -> System.Management.ManagementObject
Public Sub New (scopeString As String, pathString As String, options As ObjectGetOptions)
參數
- scopeString
- String
WMI 物件的範圍。
- pathString
- String
WMI 物件路徑。
- options
- ObjectGetOptions
A ObjectGetOptions 表示取得 WMI 物件的額外選項。
範例
以下範例初始化一個新的類別實例 ManagementObject ,並設定特定的 WMI 路徑與選項。
using System;
using System.Management;
class Sample
{
public static int Main(string[] args)
{
ObjectGetOptions opt =
new ObjectGetOptions(null, System.TimeSpan.MaxValue, true);
ManagementObject o =
new ManagementObject(
"root\\MyNamespace", "MyClass", opt);
return 0;
}
}
Imports System.Management
Class Sample_ManagementClass
Public Overloads Shared Function Main( _
ByVal args() As String) As Integer
Dim opt As New ObjectGetOptions( _
Nothing, System.TimeSpan.MaxValue, True)
Dim o As New ManagementObject( _
"root\MyNamespace", "MyClass", opt)
Return 0
End Function
End Class
備註
詳情請參見等效的超載。
.NET Framework 安全性
完全信任當下的來電者。 此成員無法被部分受信任的程式碼使用。 欲了解更多資訊,請參閱 「部分受信任程式碼的函式庫使用」。