G
Guest
Hi all,
Using WMI I am attempting to catch and exception when doing a managementscope.connect operation.
From the looks of things, this method starts a new worker thread through Interop that then executes the method.
My problem is that regardless of what all I use in my catch statements, the system still raises the
initial dialog reporting the exception. Eventually, my app catches and handles the exception but
I cannot get the initial one. Is there a code snippet somewhere that shows how to hook into the
exception event handler in WMI or Interop? I am purposely running this against a machine that does
not have WMI enabled to ensure that an error will occur. I'm at a loss on how to handle this.
Heres a snip.... and hmmm.. sorry about the formatting....
Public Function blaa() as Boolean
Dim options As New ConnectionOptions()
Dim scope As ManagementScope
Dim blah As String
options.Username = "xxxx\Administrator"
options.Password = "****"
scope = New ManagementScope("\\" & "10.0.1.10" & "\root\cimv2", options)
Try
scope.Connect()
return true
Catch e As System.Management.ManagementException
Return False
Catch e As System.Runtime.InteropServices.COMException
Return False
Catch e As System.Exception
Return False
Catch e As Exception
Return False
End Try
End Function
Using WMI I am attempting to catch and exception when doing a managementscope.connect operation.
From the looks of things, this method starts a new worker thread through Interop that then executes the method.
My problem is that regardless of what all I use in my catch statements, the system still raises the
initial dialog reporting the exception. Eventually, my app catches and handles the exception but
I cannot get the initial one. Is there a code snippet somewhere that shows how to hook into the
exception event handler in WMI or Interop? I am purposely running this against a machine that does
not have WMI enabled to ensure that an error will occur. I'm at a loss on how to handle this.
Heres a snip.... and hmmm.. sorry about the formatting....
Public Function blaa() as Boolean
Dim options As New ConnectionOptions()
Dim scope As ManagementScope
Dim blah As String
options.Username = "xxxx\Administrator"
options.Password = "****"
scope = New ManagementScope("\\" & "10.0.1.10" & "\root\cimv2", options)
Try
scope.Connect()
return true
Catch e As System.Management.ManagementException
Return False
Catch e As System.Runtime.InteropServices.COMException
Return False
Catch e As System.Exception
Return False
Catch e As Exception
Return False
End Try
End Function