ManagementScope 类

定义

表示管理操作的范围(命名空间)。

public ref class ManagementScope : ICloneable
public class ManagementScope : ICloneable
[System.ComponentModel.TypeConverter(typeof(System.Management.ManagementScopeConverter))]
public class ManagementScope : ICloneable
type ManagementScope = class
    interface ICloneable
[<System.ComponentModel.TypeConverter(typeof(System.Management.ManagementScopeConverter))>]
type ManagementScope = class
    interface ICloneable
Public Class ManagementScope
Implements ICloneable
继承
ManagementScope
属性
实现

示例

以下示例使用特定路径初始化新的 ManagementScope ,然后将范围对象连接到 WMI 命名空间。 该示例连接到远程计算机上的命名空间。

using System;
using System.Management;
public class RemoteConnect
{
    public static void Main()
    {
        /*// Build an options object for the remote connection
        //   if you plan to connect to the remote
        //   computer with a different user name
        //   and password than the one you are currently using

             ConnectionOptions options =
                 new ConnectionOptions();

             // and then set the options.Username and
             // options.Password properties to the correct values
             // and also set
             // options.Authority = "ntlmdomain:DOMAIN";
             // and replace DOMAIN with the remote computer's
             // domain.  You can also use Kerberos instead
             // of ntlmdomain.
        */

        // Make a connection to a remote computer.
        // Replace the "FullComputerName" section of the
        // string "\\\\FullComputerName\\root\\cimv2" with
        // the full computer name or IP address of the
        // remote computer.
        ManagementScope scope =
            new ManagementScope(
            "\\\\FullComputerName\\root\\cimv2");
        scope.Connect();

        // Use this code if you are connecting with a
        // different user name and password:
        //
        // ManagementScope scope =
        //    new ManagementScope(
        //        "\\\\FullComputerName\\root\\cimv2", options);
        // scope.Connect();

        //Query system for Operating System information
        ObjectQuery query = new ObjectQuery(
            "SELECT * FROM Win32_OperatingSystem");
        ManagementObjectSearcher searcher =
            new ManagementObjectSearcher(scope,query);

        ManagementObjectCollection queryCollection = searcher.Get();
        foreach ( ManagementObject m in queryCollection)
        {
            // Display the remote computer information
            Console.WriteLine("Computer Name : {0}",
                m["csname"]);
            Console.WriteLine("Windows Directory : {0}",
                m["WindowsDirectory"]);
            Console.WriteLine("Operating System: {0}",
                m["Caption"]);
            Console.WriteLine("Version: {0}", m["Version"]);
            Console.WriteLine("Manufacturer : {0}",
                m["Manufacturer"]);
        }
    }
}
Imports System.Management
Public Class RemoteConnect

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


        ' Build an options object for the remote connection
        ' if you plan to connect to the remote
        ' computer with a different user name
        ' and password than the one you are currently using

        ' Dim options As ConnectionOptions 
        ' options = new ConnectionOptions()

        ' Then set the options.Username and 
        ' options.Password properties to the correct values
        ' and also set 
        ' options.Authority = "ntlmdomain:DOMAIN"
        ' and replace DOMAIN with the remote computer's
        ' domain.  You can also use Kerberos instead
        ' of ntlmdomain.


        ' Make a connection to a remote computer.
        ' Replace the "FullComputerName" section of the
        ' string "\\FullComputerName\root\cimv2" with
        ' the full computer name or IP address of the
        ' remote computer.
        Dim scope As ManagementScope
        scope = New ManagementScope( _
            "\\FullComputerName\root\cimv2")
        scope.Connect()

        ' Use this code if you are connecting with a 
        ' different user name and password:
        '
        ' Dim scope As ManagementScope
        ' scope = New ManagementScope( _
        '     "\\FullComputerName\root\cimv2", options)
        ' scope.Connect()

        ' Query system for Operating System information
        Dim query As ObjectQuery
        query = New ObjectQuery( _
            "SELECT * FROM Win32_OperatingSystem")
        Dim searcher As ManagementObjectSearcher
        searcher = _
            New ManagementObjectSearcher(scope, query)

        Dim queryCollection As ManagementObjectCollection
        queryCollection = searcher.Get()

        Dim m As ManagementObject
        For Each m In queryCollection
            ' Display the remote computer information
            Console.WriteLine("Computer Name : {0}", _
                m("csname"))
            Console.WriteLine("Windows Directory : {0}", _
                m("WindowsDirectory"))
            Console.WriteLine("Operating System: {0}", _
                m("Caption"))
            Console.WriteLine("Version: {0}", m("Version"))
            Console.WriteLine("Manufacturer : {0}", _
                m("Manufacturer"))
        Next

        Return 0
    End Function
End Class

构造函数

ManagementScope()

使用默认值初始化 ManagementScope 类的新实例。 这是无参数构造函数。

ManagementScope(ManagementPath)

初始化 ManagementScope 类的、表示指定范围路径的新实例。

ManagementScope(ManagementPath, ConnectionOptions)

使用指定选项初始化 ManagementScope 类的、表示指定范围路径的新实例。

ManagementScope(String)

初始化 ManagementScope 类的、表示指定范围路径的新实例。

ManagementScope(String, ConnectionOptions)

使用指定选项初始化 ManagementScope 类的、表示指定范围路径的新实例。

属性

IsConnected

获取一个值,该值指示 ManagementScope 当前是否绑定到了某个 WMI 服务器和命名空间。

Options

获取或设置有关创建 WMI 连接的选项。

Path

获取或设置 ManagementScope 的路径。

方法

Clone()

返回对象的一个副本。

Connect()

将此 ManagementScope 连接到实际的 WMI 范围。

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

显式接口实现

ICloneable.Clone()

创建作为当前实例副本的新对象。

适用于