ConnectionOptions ConnectionOptions ConnectionOptions ConnectionOptions Constructors

定義

オーバーロード

ConnectionOptions() ConnectionOptions() ConnectionOptions()

接続操作のための ConnectionOptions クラスの新しいインスタンスを、既定値を使用して初期化します。Initializes a new instance of the ConnectionOptions class for the connection operation, using default values. これはパラメーターなしのコンストラクターです。This is the parameterless constructor.

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

新しい接続オプションを作成します。Creates a new ConnectionOption.

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

指定した値を使用して、WMI 接続に使用する ConnectionOptions クラスの新しいインスタンスを初期化します。Initializes a new instance of the ConnectionOptions class to be used for a WMI connection, using the specified values.

ConnectionOptions() ConnectionOptions() ConnectionOptions()

接続操作のための ConnectionOptions クラスの新しいインスタンスを、既定値を使用して初期化します。Initializes a new instance of the ConnectionOptions class for the connection operation, using default values. これはパラメーターなしのコンストラクターです。This is the parameterless constructor.

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

次の例では、リモートコンピューターに接続し、リモートコンピューターのオペレーティングシステムに関する情報を表示します。The following example connects to a remote computer and displays information about the operating system on the remote computer. 既定ConnectionOptionsの接続オプションを使用してリモートコンピューターに接続するためのが作成されます。A ConnectionOptions is created to connect to the remote computer with default connection options.

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 セキュリティ.NET Framework Security

直前の呼び出し元に対する完全な信頼。Full trust for the immediate caller. このメンバーは、部分的に信頼されているコードから使用することはできません。This member cannot be used by partially trusted code. 詳細については、「部分信頼コードからのライブラリの使用」を参照してください。For more information, see Using Libraries from Partially Trusted Code.

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

新しい接続オプションを作成します。Creates a new 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 String String String

接続に使用するロケール。The locale to be used for the connection.

username
String String String String

接続に使用するユーザー名。The user name to be used for the connection. null の場合は、現在ログオンしているユーザーの資格情報を使用します。If null, the credentials of the currently logged-on user are used.

password
SecureString SecureString SecureString SecureString

指定されたユーザー名のパスワード。The password for the given user name. ユーザー名も null の場合は、現在ログオンしているユーザーの資格情報を使用します。If the user name is also null, the credentials used will be those of the currently logged-on user.

authority
String String String String

指定したユーザーを認証するために使用する証明機関。The authority to be used to authenticate the specified user.

impersonation
ImpersonationLevel ImpersonationLevel ImpersonationLevel ImpersonationLevel

接続に使用する COM 偽装レベル。The COM impersonation level to be used for the connection.

authentication
AuthenticationLevel AuthenticationLevel AuthenticationLevel AuthenticationLevel

接続に使用する COM 認証レベル。The COM authentication level to be used for the connection.

enablePrivileges
Boolean Boolean Boolean Boolean

特別なユーザー特権を有効にするには true。それ以外の場合は false。true to enable special user privileges; otherwise, false. このパラメーターは、特別な Windows NT ユーザー特権を必要とする操作を実行する場合にだけ使用してください。This parameter should only be used when performing an operation that requires special Windows NT user privileges.

context
ManagementNamedValueCollection ManagementNamedValueCollection ManagementNamedValueCollection ManagementNamedValueCollection

プロバイダーに渡される、プロバイダー固有の名前付き値がペアとなったオブジェクト。A provider-specific, named value pairs object to be passed through to the provider.

timeout
TimeSpan TimeSpan TimeSpan TimeSpan

将来使用するために予約されています。Reserved for future use.

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

指定した値を使用して、WMI 接続に使用する ConnectionOptions クラスの新しいインスタンスを初期化します。Initializes a new instance of the ConnectionOptions class to be used for a WMI connection, using the specified values.

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 String String String

接続に使用するロケール。The locale to be used for the connection.

username
String String String String

接続に使用するユーザー名。The user name to be used for the connection. null の場合は、現在ログオンしているユーザーの資格情報を使用します。If null, the credentials of the currently logged-on user are used.

password
String String String String

指定されたユーザー名のパスワード。The password for the given user name. ユーザー名も null の場合は、現在ログオンしているユーザーの資格情報を使用します。If the user name is also null, the credentials used will be those of the currently logged-on user.

authority
String String String String

指定したユーザーを認証するために使用する証明機関。The authority to be used to authenticate the specified user.

impersonation
ImpersonationLevel ImpersonationLevel ImpersonationLevel ImpersonationLevel

接続に使用する COM 偽装レベル。The COM impersonation level to be used for the connection.

authentication
AuthenticationLevel AuthenticationLevel AuthenticationLevel AuthenticationLevel

接続に使用する COM 認証レベル。The COM authentication level to be used for the connection.

enablePrivileges
Boolean Boolean Boolean Boolean

特別なユーザー特権を有効にするには true。それ以外の場合はfalsetrue to enable special user privileges; otherwise, false. このパラメーターは、特別な Windows NT ユーザー特権を必要とする操作を実行する場合にだけ使用してください。This parameter should only be used when performing an operation that requires special Windows NT user privileges.

context
ManagementNamedValueCollection ManagementNamedValueCollection ManagementNamedValueCollection ManagementNamedValueCollection

プロバイダーに渡される、プロバイダー固有の名前付き値がペアとなったオブジェクト。A provider-specific, named value pairs object to be passed through to the provider.

timeout
TimeSpan TimeSpan TimeSpan TimeSpan

将来使用するために予約されています。Reserved for future use.

次の例では、リモートコンピューターに接続し、リモートコンピューターのオペレーティングシステムに関する情報を表示します。The following example connects to a remote computer and displays information about the operating system on the remote computer. 必要ConnectionOptionsな接続オプションを使用してリモートコンピューターに接続するためのが作成されます。A ConnectionOptions is created to connect to the remote computer with the desired connection options.

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 セキュリティ.NET Framework Security

直前の呼び出し元に対する完全な信頼。Full trust for the immediate caller. このメンバーは、部分的に信頼されているコードから使用することはできません。This member cannot be used by partially trusted code. 詳細については、「部分信頼コードからのライブラリの使用」を参照してください。For more information, see Using Libraries from Partially Trusted Code.

適用対象