WMI wont throw exception ??

aikeru

New member
Joined
Oct 14, 2007
Messages
3
Programming Experience
1-3
Hello. I'm new to this forum. I've been searching frantically through Google and anywhere else I can find on this particular problem and I'm completely stumped.

I have an application which creates multiple threads. Each thread may try to do a WMI query but when I try .Connect() or .Get() method, even with Try/Catch and stepping through the debugger that part of code just "stops running". The program is still running, however.

It doesn't generate an exception or anything. :(

I've also been looking for alternative ways to test if I can get a WMI connection but I'm not sure what else I can try for that, either.

Can anyone help?
 
Last edited:
Here you go:
For example:
VB.NET:
Public Function CheckWMI(ByVal srvName As String) As Boolean
      Dim scope As System.Management.ManagementScope = New System.Management.ManagementScope
        scope = New System.Management.ManagementScope("\\" & srvName & "\root\cimv2")
        Try
            scope.Connect() 'Debugger reaches this line
        Catch ex As Exception
            'We'll never get here :(
        End Try
      'Or here, either.
End Function

For example, assume "srvName" has been set to "www.google.com" which is bunk, but I'm trying to write a sound application that can handle anything the user might throw at it.
 
Last edited:
I've done very little WMI work so this is untested, but from what I've read in the documentation you should be able to set the Timeout property of the ManagementScope object before calling Connect. That should force it to return even if it fails, after which you can test the IsConnected property to know whether the operation was successful.
 
Thanks for the info! :) Turns out it actually wasn't dying but just took a very long time to come back.
Now that I realized this, I had the threads create other threads to check the WMI, which they monitor for completion. This way, the quicker stuff gets taken care of immediately and the slower stuff can update when it has the opportunity.
 
Last edited:
Back
Top