Discussion:
Specify a timeout for WMI connections via .Net
(too old to reply)
Dan Thomson
2009-05-27 13:01:01 UTC
Permalink
I'm coding a multi-threaded app in VB .Net 2005 that connects to WMI on many
remote systems. Some systems have issues that are causing their thread to
hang when I try to connect. Is there a way to specify that there should be a
timeout when attempting to connect so that the connection will fail and I can
move on and gracefully exit the thread?

Here is one flavor of what I've tried

Dim strScope As String = "\\ComputerName\root\cimv2"
Dim WMIOptions As New ConnectionOptions
Dim WMIScope As New ManagementScope

WMIOptions.Impersonation = ImpersonationLevel.Impersonate
WMIOptions.Timeout = New TimeSpan(0, 60, 0)
WMIScope = New ManagementScope(strScope, WMIOptions)
WMIScope.Connect()
'The code never reaches this point on some systems.


I've tried specifying WMIScope.Options.Timeout and WMIOptions.Timeout.
Neither seem to work.

Dan
Gerry Hickman
2009-06-03 22:06:07 UTC
Permalink
Hello Dan,

I don't know about .NET, but my recollection from using WMI is that you
can NOT set the timeout.

The workaround I use, is to issue a ping to the remote host before
trying to connect to WMI. Look out for firewall if you use ping.
Post by Dan Thomson
I'm coding a multi-threaded app in VB .Net 2005 that connects to WMI on many
remote systems. Some systems have issues that are causing their thread to
hang when I try to connect. Is there a way to specify that there should be a
timeout when attempting to connect so that the connection will fail and I can
move on and gracefully exit the thread?
Here is one flavor of what I've tried
Dim strScope As String = "\\ComputerName\root\cimv2"
Dim WMIOptions As New ConnectionOptions
Dim WMIScope As New ManagementScope
WMIOptions.Impersonation = ImpersonationLevel.Impersonate
WMIOptions.Timeout = New TimeSpan(0, 60, 0)
WMIScope = New ManagementScope(strScope, WMIOptions)
WMIScope.Connect()
'The code never reaches this point on some systems.
I've tried specifying WMIScope.Options.Timeout and WMIOptions.Timeout.
Neither seem to work.
Dan
--
Gerry Hickman (London UK)
Dan Thomson
2009-06-03 23:19:01 UTC
Permalink
Thanks Gerry,

I do all kinds of preflight kind of checks, to include ping and DNS name
resolution prior to attempting to connect to a remote system. The problem is
my ManagementScope connect() method hangs when I attempt to connect to a
system that is online, but has some sort of WMI issue. I'm having to
investigate how to track my worker threads and kill those that look hung.

I would have thought this simple feature would be available via .Net, but.....

Dan
Post by Gerry Hickman
Hello Dan,
I don't know about .NET, but my recollection from using WMI is that you
can NOT set the timeout.
The workaround I use, is to issue a ping to the remote host before
trying to connect to WMI. Look out for firewall if you use ping.
Post by Dan Thomson
I'm coding a multi-threaded app in VB .Net 2005 that connects to WMI on many
remote systems. Some systems have issues that are causing their thread to
hang when I try to connect. Is there a way to specify that there should be a
timeout when attempting to connect so that the connection will fail and I can
move on and gracefully exit the thread?
Here is one flavor of what I've tried
Dim strScope As String = "\\ComputerName\root\cimv2"
Dim WMIOptions As New ConnectionOptions
Dim WMIScope As New ManagementScope
WMIOptions.Impersonation = ImpersonationLevel.Impersonate
WMIOptions.Timeout = New TimeSpan(0, 60, 0)
WMIScope = New ManagementScope(strScope, WMIOptions)
WMIScope.Connect()
'The code never reaches this point on some systems.
I've tried specifying WMIScope.Options.Timeout and WMIOptions.Timeout.
Neither seem to work.
Dan
--
Gerry Hickman (London UK)
Gerry Hickman
2009-06-23 22:42:14 UTC
Permalink
Hi Dan,

I wonder what kind of "WMI issue"?

I've been using WMI against thousands of machines for a while and
provided I can get a ping response, I've had very few problems, although
we do have software firewall disabled which may help.

I don't use .NET with WMI right now, mainly because it just seems to be
wrappers around the same calls?
Post by Dan Thomson
Thanks Gerry,
I do all kinds of preflight kind of checks, to include ping and DNS name
resolution prior to attempting to connect to a remote system. The problem is
my ManagementScope connect() method hangs when I attempt to connect to a
system that is online, but has some sort of WMI issue. I'm having to
investigate how to track my worker threads and kill those that look hung.
I would have thought this simple feature would be available via .Net, but.....
Dan
Post by Gerry Hickman
Hello Dan,
I don't know about .NET, but my recollection from using WMI is that you
can NOT set the timeout.
The workaround I use, is to issue a ping to the remote host before
trying to connect to WMI. Look out for firewall if you use ping.
Post by Dan Thomson
I'm coding a multi-threaded app in VB .Net 2005 that connects to WMI on many
remote systems. Some systems have issues that are causing their thread to
hang when I try to connect. Is there a way to specify that there should be a
timeout when attempting to connect so that the connection will fail and I can
move on and gracefully exit the thread?
Here is one flavor of what I've tried
Dim strScope As String = "\\ComputerName\root\cimv2"
Dim WMIOptions As New ConnectionOptions
Dim WMIScope As New ManagementScope
WMIOptions.Impersonation = ImpersonationLevel.Impersonate
WMIOptions.Timeout = New TimeSpan(0, 60, 0)
WMIScope = New ManagementScope(strScope, WMIOptions)
WMIScope.Connect()
'The code never reaches this point on some systems.
I've tried specifying WMIScope.Options.Timeout and WMIOptions.Timeout.
Neither seem to work.
Dan
--
Gerry Hickman (London UK)
--
Gerry Hickman (London UK)
Gerry Hickman
2009-06-03 22:06:07 UTC
Permalink
Hello Dan,

I don't know about .NET, but my recollection from using WMI is that you
can NOT set the timeout.

The workaround I use, is to issue a ping to the remote host before
trying to connect to WMI. Look out for firewall if you use ping.
Post by Dan Thomson
I'm coding a multi-threaded app in VB .Net 2005 that connects to WMI on many
remote systems. Some systems have issues that are causing their thread to
hang when I try to connect. Is there a way to specify that there should be a
timeout when attempting to connect so that the connection will fail and I can
move on and gracefully exit the thread?
Here is one flavor of what I've tried
Dim strScope As String = "\\ComputerName\root\cimv2"
Dim WMIOptions As New ConnectionOptions
Dim WMIScope As New ManagementScope
WMIOptions.Impersonation = ImpersonationLevel.Impersonate
WMIOptions.Timeout = New TimeSpan(0, 60, 0)
WMIScope = New ManagementScope(strScope, WMIOptions)
WMIScope.Connect()
'The code never reaches this point on some systems.
I've tried specifying WMIScope.Options.Timeout and WMIOptions.Timeout.
Neither seem to work.
Dan
--
Gerry Hickman (London UK)
Continue reading on narkive:
Search results for 'Specify a timeout for WMI connections via .Net' (Questions and Answers)
3
replies
Briefly describe the Microsoft's 2000 DNS management?
started 2006-08-17 22:05:37 UTC
computer networking
Loading...