Home | Index | Dotnet4all Snippets | Submit resources
About | Mail us 





WMI Com Interop exception handling (Tuesday, January 03, 2006)



Found the following interesting discussion in the Newsgroups:

WMI Com Interop exception handling
by:Anonymous

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


 Reply:
by:Anonymous

 Anyone have any idea's? I searched over in the Interop forum but havn't seen much. Is this something that I'll need to use reflection for possibly? I'm fairly new to this .Net so I'm not real clear on reflection usage. Btw, I've added handlers for current domain unhandled exceptions and for app threadexceptions and I still can't catch the error.
Thanks to anyone with any ideas ! :)




 Reply:
by:Anonymous

 Anyone have any ideas on this? I've looked over in the interop forum but havn't seen anything jump out at me. I wonder if this is something that I need to use reflection for perhaps? I'm new to this .Net stuff so I'm not realy clear on how that works. BTW, I've added handlers for the current domain and the app thread exceptions and I still can't catch the initial error.

Thanks to anyone with any ideas ! :)



Posted by Xander Zelders



0 Comments:

Post a Comment

<< Home

 
Previous Posts
    - Problem With Mailto Start Process
    - Comboboxes in windows forms datagrid
    - Sometimes I want to skip a page - How to do that
    - FxCop Error on command button
    - How to scroll down on listView (programmatically)
    - Open a file save as byte
    - How to add a property to an inherited tool?
    - Retrieve Domain Names
    - listView + events
    - RTC and VB.NET



Disclaimer & Terms of Use | DotNet4All.Com concept & © 2004 - 2007 by Zelders² - Holland