ConnectionOptions Class
Specifies all settings required to make a WMI connection.
For a list of all members of this type, see ConnectionOptions Members.
System.Object
System.Management.ManagementOptions
System.Management.ConnectionOptions
[Visual Basic] Public Class ConnectionOptions Inherits ManagementOptions [C#] public class ConnectionOptions : ManagementOptions [C++] public __gc class ConnectionOptions : public ManagementOptions [JScript] public class ConnectionOptions extends ManagementOptions
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Example
[C#] using System; using System.Management; // This example demonstrates how to connect to remote machine // using supplied credentials. class Sample_ConnectionOptions { public static int Main(string[] args) { ConnectionOptions options = new ConnectionOptions(); options.Username = UserName; //could be in domain\user format options.Password = SecurelyStoredPassword; ManagementScope scope = new ManagementScope( "\\\\servername\\root\\cimv2", options); try { scope.Connect(); ManagementObject disk = new ManagementObject( scope, new ManagementPath("Win32_logicaldisk='c:'"), null); disk.Get(); } catch (Exception e) { Console.WriteLine("Failed to connect: " + e.Message); } return 0; } } [Visual Basic] Imports System Imports System.Management ' This example demonstrates how to connect to remote machine ' using supplied credentials. Class Sample_ConnectionOptions Overloads Public Shared Function Main(args() As String) As Integer Dim options As New ConnectionOptions() options.Username = UserName options.Password = SecurelyStoredPassword Dim scope As New ManagementScope("\\servername\root\cimv2", options) Try scope.Connect() Dim disk As New ManagementObject(scope, _ New ManagementPath("Win32_logicaldisk='c:'"), Nothing) disk.Get() Catch e As UnauthorizedAccessException Console.WriteLine(("Failed to connect: " + e.Message)) End Try Return 0 End Function End Class
[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Namespace: System.Management
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
Assembly: System.Management (in System.Management.dll)