ManagementScope 类

定义

表示管理操作的范围(命名空间)。Represents a scope (namespace) for management operations.

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

示例

下面的示例使用特定路径初始化新 ManagementScope,然后将作用域对象连接到 WMI 命名空间。The following example initializes a new ManagementScope with a specific path and then connects the scope object to a WMI namespace. 该示例连接到远程计算机上的命名空间。The example connects to a namespace on a remote computer.

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 类的新实例。Initializes a new instance of the ManagementScope class, with default values. 这就是无参数构造函数。This is the parameterless constructor.

ManagementScope(ManagementPath)

初始化 ManagementScope 类的、表示指定范围路径的新实例。Initializes a new instance of the ManagementScope class representing the specified scope path.

ManagementScope(ManagementPath, ConnectionOptions)

使用指定选项初始化 ManagementScope 类的、表示指定范围路径的新实例。Initializes a new instance of the ManagementScope class representing the specified scope path, with the specified options.

ManagementScope(String)

初始化 ManagementScope 类的、表示指定范围路径的新实例。Initializes a new instance of the ManagementScope class representing the specified scope path.

ManagementScope(String, ConnectionOptions)

使用指定选项初始化 ManagementScope 类的、表示指定范围路径的新实例。Initializes a new instance of the ManagementScope class representing the specified scope path, with the specified options.

属性

IsConnected

获取一个值,该值指示 ManagementScope 当前是否绑定到了某个 WMI 服务器和命名空间。Gets a value indicating whether the ManagementScope is currently bound to a WMI server and namespace.

Options

获取或设置有关创建 WMI 连接的选项。Gets or sets options for making the WMI connection.

Path

获取或设置 ManagementScope 的路径。Gets or sets the path for the ManagementScope.

方法

Clone()

返回对象的一个副本。Returns a copy of the object.

Connect()

将此 ManagementScope 连接到实际的 WMI 范围。Connects this ManagementScope to the actual WMI scope.

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

显式接口实现

ICloneable.Clone()

创建作为当前实例副本的新对象。Creates a new object that is a copy of the current instance.

适用于