Connect to a remote server with different user/password using .NET/WMI

I’ve seen various posts in the newsgroups how to use .NET to connect to a remote server to collect WMI information. 


Dim options As New ConnectionOptions()
options.Username = “DomainUserId”
options.Password = “password”

Dim scope As New ManagementScope(“\ServerNamerootcimv2”, options)
Dim strSVCquery As String = ConfigurationSettings.AppSettings(“NICquery”)

Dim objNICQuery As New WqlObjectQuery(strSVCquery)
Dim objNICsearcher As New ManagementObjectSearcher(scope, objNICQuery)

Dim envVar As New ManagementObject()

Dim objNICItem As PropertyData
Dim strNICColName As String

scope.Connect()
For Each envVar In objNICsearcher.Get
        For Each objNICItem In envVar.Properties
            strNICColName = objNICItem.Name
            If Not IsArray(objNICItem.Value) Then
                Console.WriteLine(“Item is NOT an array — ” & strNICColName)
            Else
                Console.WriteLine(“Item is an array — ” & strNICColName)
            End If
        Next
Next

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: