ManagementScope Konstruktory

Definicja

Inicjuje nowe wystąpienie klasy ManagementScope.

Przeciążenia

ManagementScope()

Inicjuje ManagementScope nowe wystąpienie klasy z wartościami domyślnymi. Jest to konstruktor bez parametrów.

ManagementScope(ManagementPath)

Inicjuje ManagementScope nowe wystąpienie klasy reprezentujące określoną ścieżkę zakresu.

ManagementScope(String)

Inicjuje ManagementScope nowe wystąpienie klasy reprezentujące określoną ścieżkę zakresu.

ManagementScope(ManagementPath, ConnectionOptions)

Inicjuje ManagementScope nowe wystąpienie klasy reprezentujące określoną ścieżkę zakresu z określonymi opcjami.

ManagementScope(String, ConnectionOptions)

Inicjuje ManagementScope nowe wystąpienie klasy reprezentujące określoną ścieżkę zakresu z określonymi opcjami.

ManagementScope()

Źródło:
ManagementScope.cs
Źródło:
ManagementScope.cs
Źródło:
ManagementScope.cs

Inicjuje ManagementScope nowe wystąpienie klasy z wartościami domyślnymi. Jest to konstruktor bez parametrów.

public:
 ManagementScope();
public ManagementScope ();
Public Sub New ()

Uwagi

Jeśli obiekt nie ma żadnych właściwości ustawionych przed połączeniem, jest inicjowany przy użyciu wartości domyślnych (na przykład komputera lokalnego i przestrzeni nazw root\cimv2).

Zabezpieczenia.NET Framework

Pełne zaufanie do bezpośredniego wywołującego. Ten element członkowski nie może być używany przez kod częściowo zaufany. Aby uzyskać więcej informacji, zobacz Using Libraries from Partially Trusted Code (Używanie bibliotek z częściowo zaufanego kodu).

Dotyczy

ManagementScope(ManagementPath)

Źródło:
ManagementScope.cs
Źródło:
ManagementScope.cs
Źródło:
ManagementScope.cs

Inicjuje ManagementScope nowe wystąpienie klasy reprezentujące określoną ścieżkę zakresu.

public:
 ManagementScope(System::Management::ManagementPath ^ path);
public ManagementScope (System.Management.ManagementPath path);
new System.Management.ManagementScope : System.Management.ManagementPath -> System.Management.ManagementScope
Public Sub New (path As ManagementPath)

Parametry

path
ManagementPath

Element ManagementPath zawierający ścieżkę do serwera i przestrzeni nazw dla elementu ManagementScope.

Uwagi

Zabezpieczenia.NET Framework

Pełne zaufanie do bezpośredniego wywołującego. Ten element członkowski nie może być używany przez kod częściowo zaufany. Aby uzyskać więcej informacji, zobacz Using Libraries from Partially Trusted Code (Używanie bibliotek z częściowo zaufanego kodu).

Dotyczy

ManagementScope(String)

Źródło:
ManagementScope.cs
Źródło:
ManagementScope.cs
Źródło:
ManagementScope.cs

Inicjuje ManagementScope nowe wystąpienie klasy reprezentujące określoną ścieżkę zakresu.

public:
 ManagementScope(System::String ^ path);
public ManagementScope (string path);
new System.Management.ManagementScope : string -> System.Management.ManagementScope
Public Sub New (path As String)

Parametry

path
String

Ścieżka serwera i przestrzeni nazw dla elementu ManagementScope.

Przykłady

Poniższy przykład inicjuje nową ManagementScope ścieżkę z określoną ścieżką, a następnie łączy obiekt zakresu z przestrzenią nazw usługi WMI. Przykład łączy się z przestrzenią nazw na komputerze zdalnym.

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

Uwagi

Zabezpieczenia.NET Framework

Pełne zaufanie do bezpośredniego wywołującego. Ten element członkowski nie może być używany przez kod częściowo zaufany. Aby uzyskać więcej informacji, zobacz Using Libraries from Partially Trusted Code (Używanie bibliotek z częściowo zaufanego kodu).

Dotyczy

ManagementScope(ManagementPath, ConnectionOptions)

Źródło:
ManagementScope.cs
Źródło:
ManagementScope.cs
Źródło:
ManagementScope.cs

Inicjuje ManagementScope nowe wystąpienie klasy reprezentujące określoną ścieżkę zakresu z określonymi opcjami.

public:
 ManagementScope(System::Management::ManagementPath ^ path, System::Management::ConnectionOptions ^ options);
public ManagementScope (System.Management.ManagementPath path, System.Management.ConnectionOptions options);
new System.Management.ManagementScope : System.Management.ManagementPath * System.Management.ConnectionOptions -> System.Management.ManagementScope
Public Sub New (path As ManagementPath, options As ConnectionOptions)

Parametry

path
ManagementPath

Element ManagementPath zawierający ścieżkę do serwera i przestrzeni nazw dla elementu ManagementScope.

options
ConnectionOptions

Zawierające ConnectionOptions opcje połączenia.

Uwagi

Zabezpieczenia.NET Framework

Pełne zaufanie do bezpośredniego wywołującego. Ten element członkowski nie może być używany przez kod częściowo zaufany. Aby uzyskać więcej informacji, zobacz Using Libraries from Partially Trusted Code (Używanie bibliotek z częściowo zaufanego kodu).

Dotyczy

ManagementScope(String, ConnectionOptions)

Źródło:
ManagementScope.cs
Źródło:
ManagementScope.cs
Źródło:
ManagementScope.cs

Inicjuje ManagementScope nowe wystąpienie klasy reprezentujące określoną ścieżkę zakresu z określonymi opcjami.

public:
 ManagementScope(System::String ^ path, System::Management::ConnectionOptions ^ options);
public ManagementScope (string path, System.Management.ConnectionOptions options);
new System.Management.ManagementScope : string * System.Management.ConnectionOptions -> System.Management.ManagementScope
Public Sub New (path As String, options As ConnectionOptions)

Parametry

path
String

Serwer i przestrzeń nazw dla programu ManagementScope.

options
ConnectionOptions

Element ConnectionOptions zawierający opcje połączenia.

Przykłady

Poniższy przykład inicjuje nową ManagementScope ścieżkę z określoną ścieżką, a następnie łączy obiekt zakresu z przestrzenią nazw usługi WMI. Przykład łączy się z przestrzenią nazw na komputerze zdalnym.

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

Uwagi

Zabezpieczenia.NET Framework

Pełne zaufanie do bezpośredniego wywołującego. Ten element członkowski nie może być używany przez kod częściowo zaufany. Aby uzyskać więcej informacji, zobacz Using Libraries from Partially Trusted Code (Używanie bibliotek z częściowo zaufanego kodu).

Dotyczy