This documentation is archived and is not being maintained.

ConnectionOptions Class

Specifies all settings required to make a WMI connection.

For a list of all members of this type, see ConnectionOptions Members.


[Visual Basic]
Public Class ConnectionOptions
   Inherits ManagementOptions
public class ConnectionOptions : ManagementOptions
public __gc class ConnectionOptions : public ManagementOptions
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.


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(
        try {
            ManagementObject disk = new ManagementObject(
                new ManagementPath("Win32_logicaldisk='c:'"),
        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)
            Dim disk As New ManagementObject(scope, _
                New ManagementPath("Win32_logicaldisk='c:'"), Nothing)
        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 Language Filter in the upper-left corner of the page.


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)

See Also

ConnectionOptions Members | System.Management Namespace