ConnectionOptions 생성자

정의

새 ConnectionOption을 만듭니다.

오버로드

Name Description
ConnectionOptions()

기본값을 사용하여 연결 작업에 대한 클래스의 ConnectionOptions 새 인스턴스를 초기화합니다. 매개 변수가 없는 생성자입니다.

ConnectionOptions(String, String, SecureString, String, ImpersonationLevel, AuthenticationLevel, Boolean, ManagementNamedValueCollection, TimeSpan)

새 ConnectionOption을 만듭니다.

ConnectionOptions(String, String, String, String, ImpersonationLevel, AuthenticationLevel, Boolean, ManagementNamedValueCollection, TimeSpan)

지정된 값을 사용하여 WMI 연결에 사용할 클래스의 ConnectionOptions 새 인스턴스를 초기화합니다.

ConnectionOptions()

기본값을 사용하여 연결 작업에 대한 클래스의 ConnectionOptions 새 인스턴스를 초기화합니다. 매개 변수가 없는 생성자입니다.

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

예제

다음 예제에서는 원격 컴퓨터에 연결 하 고 원격 컴퓨터에 운영 체제에 대 한 정보를 표시 합니다. A ConnectionOptions 는 기본 연결 옵션을 사용하여 원격 컴퓨터에 연결하기 위해 만들어집니다.

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.
        // This example uses the default values.

        ConnectionOptions options =
            new ConnectionOptions();

        // 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", 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

        ' 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", 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

설명

.NET Framework 보안

즉시 호출자에 대한 완전 신뢰입니다. 이 멤버는 부분적으로 신뢰할 수 있는 코드에서 사용할 수 없습니다. 자세한 내용은 부분적으로 신뢰할 수 있는 코드의 라이브러리 사용을 참조하세요.

적용 대상

ConnectionOptions(String, String, SecureString, String, ImpersonationLevel, AuthenticationLevel, Boolean, ManagementNamedValueCollection, TimeSpan)

새 ConnectionOption을 만듭니다.

public:
 ConnectionOptions(System::String ^ locale, System::String ^ username, System::Security::SecureString ^ password, System::String ^ authority, System::Management::ImpersonationLevel impersonation, System::Management::AuthenticationLevel authentication, bool enablePrivileges, System::Management::ManagementNamedValueCollection ^ context, TimeSpan timeout);
public ConnectionOptions(string locale, string username, System.Security.SecureString password, string authority, System.Management.ImpersonationLevel impersonation, System.Management.AuthenticationLevel authentication, bool enablePrivileges, System.Management.ManagementNamedValueCollection context, TimeSpan timeout);
new System.Management.ConnectionOptions : string * string * System.Security.SecureString * string * System.Management.ImpersonationLevel * System.Management.AuthenticationLevel * bool * System.Management.ManagementNamedValueCollection * TimeSpan -> System.Management.ConnectionOptions
Public Sub New (locale As String, username As String, password As SecureString, authority As String, impersonation As ImpersonationLevel, authentication As AuthenticationLevel, enablePrivileges As Boolean, context As ManagementNamedValueCollection, timeout As TimeSpan)

매개 변수

locale
String

연결에 사용할 로캘입니다.

username
String

연결에 사용할 사용자 이름입니다. null이면 현재 로그온한 사용자의 자격 증명이 사용됩니다.

password
SecureString

지정된 사용자 이름의 암호입니다. 사용자 이름도 null인 경우 사용되는 자격 증명은 현재 로그온한 사용자의 자격 증명입니다.

authority
String

지정된 사용자를 인증하는 데 사용할 권한입니다.

impersonation
ImpersonationLevel

연결에 사용할 COM 가장 수준입니다.

authentication
AuthenticationLevel

연결에 사용할 COM 인증 수준입니다.

enablePrivileges
Boolean

특별한 사용자 권한을 사용하도록 설정하려면 true입니다. 그렇지 않으면 false입니다. 이 매개 변수는 특별한 Windows NT 사용자 권한이 필요한 작업을 수행할 때만 사용해야 합니다.

context
ManagementNamedValueCollection

공급자에 전달될 공급자별 명명된 값 쌍 개체입니다.

timeout
TimeSpan

향후 사용을 위해 예약됨.

적용 대상

ConnectionOptions(String, String, String, String, ImpersonationLevel, AuthenticationLevel, Boolean, ManagementNamedValueCollection, TimeSpan)

지정된 값을 사용하여 WMI 연결에 사용할 클래스의 ConnectionOptions 새 인스턴스를 초기화합니다.

public:
 ConnectionOptions(System::String ^ locale, System::String ^ username, System::String ^ password, System::String ^ authority, System::Management::ImpersonationLevel impersonation, System::Management::AuthenticationLevel authentication, bool enablePrivileges, System::Management::ManagementNamedValueCollection ^ context, TimeSpan timeout);
public ConnectionOptions(string locale, string username, string password, string authority, System.Management.ImpersonationLevel impersonation, System.Management.AuthenticationLevel authentication, bool enablePrivileges, System.Management.ManagementNamedValueCollection context, TimeSpan timeout);
new System.Management.ConnectionOptions : string * string * string * string * System.Management.ImpersonationLevel * System.Management.AuthenticationLevel * bool * System.Management.ManagementNamedValueCollection * TimeSpan -> System.Management.ConnectionOptions
Public Sub New (locale As String, username As String, password As String, authority As String, impersonation As ImpersonationLevel, authentication As AuthenticationLevel, enablePrivileges As Boolean, context As ManagementNamedValueCollection, timeout As TimeSpan)

매개 변수

locale
String

연결에 사용할 로캘입니다.

username
String

연결에 사용할 사용자 이름입니다. null이면 현재 로그온한 사용자의 자격 증명이 사용됩니다.

password
String

지정된 사용자 이름의 암호입니다. 사용자 이름도 null인 경우 사용되는 자격 증명은 현재 로그온한 사용자의 자격 증명입니다.

authority
String

지정된 사용자를 인증하는 데 사용할 권한입니다.

impersonation
ImpersonationLevel

연결에 사용할 COM 가장 수준입니다.

authentication
AuthenticationLevel

연결에 사용할 COM 인증 수준입니다.

enablePrivileges
Boolean

true특별한 사용자 권한을 사용하도록 설정하려면 그렇지 않으면 . false 이 매개 변수는 특별한 Windows NT 사용자 권한이 필요한 작업을 수행할 때만 사용해야 합니다.

context
ManagementNamedValueCollection

공급자에 전달될 공급자별 명명된 값 쌍 개체입니다.

timeout
TimeSpan

향후 사용을 위해 예약됨.

예제

다음 예제에서는 원격 컴퓨터에 연결 하 고 원격 컴퓨터에 운영 체제에 대 한 정보를 표시 합니다. 원하는 연결 옵션을 사용하여 원격 컴퓨터에 연결하기 위해 A ConnectionOptions 가 만들어집니다.

using System;
using System.Management;
using System.Security;

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.
        SecureString pw = GetPassword();
        ConnectionOptions options =
            new ConnectionOptions("MS_409", "userName", pw,
            "ntlmdomain:DOMAIN",
            System.Management.ImpersonationLevel.Impersonate,
            System.Management.AuthenticationLevel.Default, true,
            null, System.TimeSpan.MaxValue);
        pw.Dispose();

        // 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", 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"]);
        }
    }

    /// <summary>
    /// Read a password from the console into a SecureString
    /// </summary>
    /// <returns>Password stored in a secure string</returns>
    public static SecureString GetPassword()
    {
        SecureString password = new SecureString();
        Console.WriteLine("Enter password: ");

        // get the first character of the password
        ConsoleKeyInfo nextKey = Console.ReadKey(true);

        while (nextKey.Key != ConsoleKey.Enter)
        {
            if (nextKey.Key == ConsoleKey.Backspace)
            {
                if (password.Length > 0)
                {
                    password.RemoveAt(password.Length - 1);

                    // erase the last * as well
                    Console.Write(nextKey.KeyChar);
                    Console.Write(" ");
                    Console.Write(nextKey.KeyChar);
                }
            }
            else
            {
                password.AppendChar(nextKey.KeyChar);
                Console.Write("*");
            }

            nextKey = Console.ReadKey(true);
        }

        Console.WriteLine();

        // lock the password down
        password.MakeReadOnly();
        return password;
    }
}
Imports System.Management
Imports System.Security

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 pw As SecureString
        pw = GetPassword()
        Dim options As ConnectionOptions
        options = New ConnectionOptions("MS_409", "userName", pw, _
             "ntlmdomain:DOMAIN", _
             System.Management.ImpersonationLevel.Impersonate, _
             System.Management.AuthenticationLevel.Default, True, _
             Nothing, System.TimeSpan.MaxValue)

        ' 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", 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


    ' Read a password from the console into a SecureString
    Public Shared Function GetPassword() As SecureString

        Dim password As New SecureString()
        Console.WriteLine("Enter password: ")

        ' get the first character of the password
        Dim nextKey As ConsoleKeyInfo
        nextKey = Console.ReadKey(True)

        While nextKey.Key <> ConsoleKey.Enter

            If nextKey.Key = ConsoleKey.Backspace Then
                If password.Length > 0 Then
                    password.RemoveAt(password.Length - 1)

                    ' erase the last * as well
                    Console.Write(nextKey.KeyChar)
                    Console.Write(" ")
                    Console.Write(nextKey.KeyChar)
                End If
            Else
                password.AppendChar(nextKey.KeyChar)
                Console.Write("*")
            End If

            nextKey = Console.ReadKey(True)
        End While

        Console.WriteLine()

        ' lock the password down
        password.MakeReadOnly()
        Return password
    End Function
End Class

설명

.NET Framework 보안

즉시 호출자에 대한 완전 신뢰입니다. 이 멤버는 부분적으로 신뢰할 수 있는 코드에서 사용할 수 없습니다. 자세한 내용은 부분적으로 신뢰할 수 있는 코드의 라이브러리 사용을 참조하세요.

적용 대상