I am trying to write VB.Net program, which would connect to remote computers and retrieve specific system information using WMI.
I must admit, that I am not experienced in VB.Net (wrote tons of programs in VB6, though, several of them using WMI). I cannot pass the first phase: connect to remote (or even local) WMI namespace.
Here is the first part of the code, which fails:
If fails either on myMgmtScope = New ... (on Windows XP) or on myMgmtScope.Connect() on Windows7.
Can someone, please, try to help me?
Thanks!
I must admit, that I am not experienced in VB.Net (wrote tons of programs in VB6, though, several of them using WMI). I cannot pass the first phase: connect to remote (or even local) WMI namespace.
Here is the first part of the code, which fails:
Code:
Imports System.Management
.
.
Dim myConnOpt As New System.Management.ConnectionOptions
With myConnOpt
.Impersonation = System.Management.ImpersonationLevel.Impersonate
.Authentication = System.Management.AuthenticationLevel.Packet
End With
Dim myMgmtScope As System.Management.ManagementScope
Dim sServer As String = "." ‘ or “<server name>”
myMgmtScope = New System.Management.ManagementScope("\" & sServer & "\root\cimv2", myConnOpt)
Try
myMgmtScope.Connect() ' connect to WMI namespace
Catch
If myMgmtScope.IsConnected = False Then
MsgBox("Could not connect to WMI namespace on \" & sServer)
Exit Sub
End If
End Try
If fails either on myMgmtScope = New ... (on Windows XP) or on myMgmtScope.Connect() on Windows7.
Can someone, please, try to help me?
Thanks!