Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

WMI Timeout with .NET question

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 01-03-2007   #1 (permalink)
Gaurhoth
Guest


 

WMI Timeout with .NET question

Does anyone have an example of using .NET classes to issue a remote WMI call
with a timeout value specified? The cmdlet will hang in certain
circumstances indefinitely... which bites if you are 5 into a list of 100
computers I haven't discovered a way to programatically
monitor/trap/break out of a hung WMI, so I'm hoping using the .NET class
will allow me to circumvent this problem.


--

gaurhoth
http://gaurhothw.spaces.live.com/



My System SpecsSystem Spec
Old 01-03-2007   #2 (permalink)
Gaurhoth
Guest


 

Re: WMI Timeout with .NET question

I should have added, that it's not a firewall type issue causing the
hang --- as it's only certain WMI calls. For instance... to the SAME
computer, I can do a

gwmi -co $cn -list
and even a
gwmi -co $cn -class win32_computersystem

but if I do a

gwmi -co $cn -class win32_service -filter "NAME like 'Symantec%AntiVirus'"

it hangs indefinitely (well I killed it at the 2 hour mark... I figured it
was safe to give up).

So in the long run, my ultimate goal is to allow the script to continue and
not have this 'hang' compromise the entire script's ability to complete.

--

gaurhoth
http://gaurhothw.spaces.live.com/


"Gaurhoth" <gaurhoth@live.com> wrote in message
news:e8T4kp0LHHA.4376@TK2MSFTNGP03.phx.gbl...
> Does anyone have an example of using .NET classes to issue a remote WMI
> call with a timeout value specified? The cmdlet will hang in certain
> circumstances indefinitely... which bites if you are 5 into a list of 100
> computers I haven't discovered a way to programatically
> monitor/trap/break out of a hung WMI, so I'm hoping using the .NET class
> will allow me to circumvent this problem.
>
>
> --
>
> gaurhoth
> http://gaurhothw.spaces.live.com/
>
>


My System SpecsSystem Spec
Old 01-03-2007   #3 (permalink)
/\/\o\/\/ [MVP]
Guest


 

Re: WMI Timeout with .NET question

you can give the timeout in the options in ticks (before setting class and
computer):

e.g. to make it 1,5 seconds :

$wmi = [wmi]''
PS H:\> $wmi.psbase.Options.timeout = 15000000
PS H:\> "$($wmi.psbase.Options.timeout)"
00:00:01.5000000

Greetings /\/\o\/\/


"Gaurhoth" wrote:

> I should have added, that it's not a firewall type issue causing the
> hang --- as it's only certain WMI calls. For instance... to the SAME
> computer, I can do a
>
> gwmi -co $cn -list
> and even a
> gwmi -co $cn -class win32_computersystem
>
> but if I do a
>
> gwmi -co $cn -class win32_service -filter "NAME like 'Symantec%AntiVirus'"
>
> it hangs indefinitely (well I killed it at the 2 hour mark... I figured it
> was safe to give up).
>
> So in the long run, my ultimate goal is to allow the script to continue and
> not have this 'hang' compromise the entire script's ability to complete.
>
> --
>
> gaurhoth
> http://gaurhothw.spaces.live.com/
>
>
> "Gaurhoth" <gaurhoth@live.com> wrote in message
> news:e8T4kp0LHHA.4376@TK2MSFTNGP03.phx.gbl...
> > Does anyone have an example of using .NET classes to issue a remote WMI
> > call with a timeout value specified? The cmdlet will hang in certain
> > circumstances indefinitely... which bites if you are 5 into a list of 100
> > computers I haven't discovered a way to programatically
> > monitor/trap/break out of a hung WMI, so I'm hoping using the .NET class
> > will allow me to circumvent this problem.
> >
> >
> > --
> >
> > gaurhoth
> > http://gaurhothw.spaces.live.com/
> >
> >

>
>

My System SpecsSystem Spec
Old 01-03-2007   #4 (permalink)
Gaurhoth
Guest


 

Re: WMI Timeout with .NET question

Using /\/\o\/\/'s example, I am able to set the timeout with below code:

PS ps:\> $wmi = [wmi]""
PS ps:\> $wmi.psbase.options.timeout = 15000000
PS ps:\> $wmi.path = "\\computer1\root\cimv2:Win32_Service.Name='Symantec
AntiVirus'"

but it does the same thing as get-wmiobject ... hangs. Grr! Part of this
scripts purpose is to find unhappy machines... but the ones that are most
unhappy are stopping the script cold.

Oh well... if anyone has any other ideas on how a script can recognize and
recover from these hangs, I'm all ears.
--

gaurhoth
http://gaurhothw.spaces.live.com/


"/\/\o\/\/ [MVP]" <oMVP@discussions.microsoft.com> wrote in message
news:8C75E2A3-9BDB-41AC-B721-3D1AC98C4852@microsoft.com...
> you can give the timeout in the options in ticks (before setting class and
> computer):
>
> e.g. to make it 1,5 seconds :
>
> $wmi = [wmi]''
> PS H:\> $wmi.psbase.Options.timeout = 15000000
> PS H:\> "$($wmi.psbase.Options.timeout)"
> 00:00:01.5000000
>
> Greetings /\/\o\/\/
>
>
> "Gaurhoth" wrote:
>
>> I should have added, that it's not a firewall type issue causing the
>> hang --- as it's only certain WMI calls. For instance... to the SAME
>> computer, I can do a
>>
>> gwmi -co $cn -list
>> and even a
>> gwmi -co $cn -class win32_computersystem
>>
>> but if I do a
>>
>> gwmi -co $cn -class win32_service -filter "NAME like
>> 'Symantec%AntiVirus'"
>>
>> it hangs indefinitely (well I killed it at the 2 hour mark... I figured
>> it
>> was safe to give up).
>>
>> So in the long run, my ultimate goal is to allow the script to continue
>> and
>> not have this 'hang' compromise the entire script's ability to complete.
>>
>> --
>>
>> gaurhoth
>> http://gaurhothw.spaces.live.com/
>>
>>
>> "Gaurhoth" <gaurhoth@live.com> wrote in message
>> news:e8T4kp0LHHA.4376@TK2MSFTNGP03.phx.gbl...
>> > Does anyone have an example of using .NET classes to issue a remote WMI
>> > call with a timeout value specified? The cmdlet will hang in certain
>> > circumstances indefinitely... which bites if you are 5 into a list of
>> > 100
>> > computers I haven't discovered a way to programatically
>> > monitor/trap/break out of a hung WMI, so I'm hoping using the .NET
>> > class
>> > will allow me to circumvent this problem.
>> >
>> >
>> > --
>> >
>> > gaurhoth
>> > http://gaurhothw.spaces.live.com/
>> >
>> >

>>
>>


My System SpecsSystem Spec
Old 01-03-2007   #5 (permalink)
/\\/\\o\\/\\/ [MVP]
Guest


 

Re: WMI Timeout with .NET question

if its only on a couple of machines try deleting the repository directory.
could be WMI is corrupted
(you can test this first in computer management on the affected computer
(Service and applications -> WMI control properties))
if this not works WMI is corrupt, delete the repository directory

h.t.h.

Greetings /\/\o\/\/
"Gaurhoth" <gaurhoth@live.com> wrote in message
news:eMX$ez1LHHA.5000@TK2MSFTNGP03.phx.gbl...
> Using /\/\o\/\/'s example, I am able to set the timeout with below code:
>
> PS ps:\> $wmi = [wmi]""
> PS ps:\> $wmi.psbase.options.timeout = 15000000
> PS ps:\> $wmi.path = "\\computer1\root\cimv2:Win32_Service.Name='Symantec
> AntiVirus'"
>
> but it does the same thing as get-wmiobject ... hangs. Grr! Part of this
> scripts purpose is to find unhappy machines... but the ones that are most
> unhappy are stopping the script cold.
>
> Oh well... if anyone has any other ideas on how a script can recognize and
> recover from these hangs, I'm all ears.
> --
>
> gaurhoth
> http://gaurhothw.spaces.live.com/
>
>
> "/\/\o\/\/ [MVP]" <oMVP@discussions.microsoft.com> wrote in message
> news:8C75E2A3-9BDB-41AC-B721-3D1AC98C4852@microsoft.com...
>> you can give the timeout in the options in ticks (before setting class
>> and
>> computer):
>>
>> e.g. to make it 1,5 seconds :
>>
>> $wmi = [wmi]''
>> PS H:\> $wmi.psbase.Options.timeout = 15000000
>> PS H:\> "$($wmi.psbase.Options.timeout)"
>> 00:00:01.5000000
>>
>> Greetings /\/\o\/\/
>>
>>
>> "Gaurhoth" wrote:
>>
>>> I should have added, that it's not a firewall type issue causing the
>>> hang --- as it's only certain WMI calls. For instance... to the SAME
>>> computer, I can do a
>>>
>>> gwmi -co $cn -list
>>> and even a
>>> gwmi -co $cn -class win32_computersystem
>>>
>>> but if I do a
>>>
>>> gwmi -co $cn -class win32_service -filter "NAME like
>>> 'Symantec%AntiVirus'"
>>>
>>> it hangs indefinitely (well I killed it at the 2 hour mark... I figured
>>> it
>>> was safe to give up).
>>>
>>> So in the long run, my ultimate goal is to allow the script to continue
>>> and
>>> not have this 'hang' compromise the entire script's ability to complete.
>>>
>>> --
>>>
>>> gaurhoth
>>> http://gaurhothw.spaces.live.com/
>>>
>>>
>>> "Gaurhoth" <gaurhoth@live.com> wrote in message
>>> news:e8T4kp0LHHA.4376@TK2MSFTNGP03.phx.gbl...
>>> > Does anyone have an example of using .NET classes to issue a remote
>>> > WMI
>>> > call with a timeout value specified? The cmdlet will hang in certain
>>> > circumstances indefinitely... which bites if you are 5 into a list of
>>> > 100
>>> > computers I haven't discovered a way to programatically
>>> > monitor/trap/break out of a hung WMI, so I'm hoping using the .NET
>>> > class
>>> > will allow me to circumvent this problem.
>>> >
>>> >
>>> > --
>>> >
>>> > gaurhoth
>>> > http://gaurhothw.spaces.live.com/
>>> >
>>> >
>>>
>>>

>


My System SpecsSystem Spec
Old 02-23-2007   #6 (permalink)
Roman
Guest


 

Re: WMI Timeout with .NET question

Hi there!

I have the same problem with some of the machines I'm trying to connect to.
Now I think I finally found a way to set a timeout!
Here is what I did:

PS H:\> $options.set_Username("user")
PS H:\> $options.set_Password("password")
PS H:\> $timeout = new-timespan -seconds 5
PS H:\> $options.set_timeout($timeout) # this didn't help with the wmi
queries at all....
PS H:\> $Scope = new-object System.Management.ManagementScope
"\\someserver\root\cimv2", $options
PS H:\> $Scope.Connect()
PS H:\>
PS H:\> $query = new-object System.Management.ObjectQuery "SELECT * FROM
Win32_OperatingSystem"
PS H:\> $searcher = new-object System.Management.ManagementObjectSearcher
$scope,$query
PS H:\>
PS H:\> $SearchOption = $searcher.get_options()
##
$SearchOption returns something like this:

ReturnImmediately : True
BlockSize : 1
Rewindable : True
UseAmendedQualifiers : False
EnsureLocatable : False
PrototypeOnly : False
DirectRead : False
EnumerateDeep : False
Context : {}
Timeout : 10675199.02:48:05.4775807


PS H:\> $SearchOption.set_timeout($timeout)
## set new timeout
after setting the timeout:

ReturnImmediately : True
BlockSize : 1
Rewindable : True
UseAmendedQualifiers : False
EnsureLocatable : False
PrototypeOnly : False
DirectRead : False
EnumerateDeep : False
Context : {}
Timeout : 00:00:05

PS H:\> $searcher.set_options($SearchOption)
PS H:\>
PS H:\> $searcher.get()
An error occurred while enumerating through a collection: Timed out .
At line:1 char:14
+ $searcher.get( <<<< )
PS H:\>

->

Hope this helps. If someone refines the code please post it

wbr
Roman

"Gaurhoth" wrote:

> Using /\/\o\/\/'s example, I am able to set the timeout with below code:
>
> PS ps:\> $wmi = [wmi]""
> PS ps:\> $wmi.psbase.options.timeout = 15000000
> PS ps:\> $wmi.path = "\\computer1\root\cimv2:Win32_Service.Name='Symantec
> AntiVirus'"
>
> but it does the same thing as get-wmiobject ... hangs. Grr! Part of this
> scripts purpose is to find unhappy machines... but the ones that are most
> unhappy are stopping the script cold.
>
> Oh well... if anyone has any other ideas on how a script can recognize and
> recover from these hangs, I'm all ears.
> --
>
> gaurhoth
> http://gaurhothw.spaces.live.com/
>
>
> "/\/\o\/\/ [MVP]" <oMVP@discussions.microsoft.com> wrote in message
> news:8C75E2A3-9BDB-41AC-B721-3D1AC98C4852@microsoft.com...
> > you can give the timeout in the options in ticks (before setting class and
> > computer):
> >
> > e.g. to make it 1,5 seconds :
> >
> > $wmi = [wmi]''
> > PS H:\> $wmi.psbase.Options.timeout = 15000000
> > PS H:\> "$($wmi.psbase.Options.timeout)"
> > 00:00:01.5000000
> >
> > Greetings /\/\o\/\/
> >
> >
> > "Gaurhoth" wrote:
> >
> >> I should have added, that it's not a firewall type issue causing the
> >> hang --- as it's only certain WMI calls. For instance... to the SAME
> >> computer, I can do a
> >>
> >> gwmi -co $cn -list
> >> and even a
> >> gwmi -co $cn -class win32_computersystem
> >>
> >> but if I do a
> >>
> >> gwmi -co $cn -class win32_service -filter "NAME like
> >> 'Symantec%AntiVirus'"
> >>
> >> it hangs indefinitely (well I killed it at the 2 hour mark... I figured
> >> it
> >> was safe to give up).
> >>
> >> So in the long run, my ultimate goal is to allow the script to continue
> >> and
> >> not have this 'hang' compromise the entire script's ability to complete.
> >>
> >> --
> >>
> >> gaurhoth
> >> http://gaurhothw.spaces.live.com/
> >>
> >>
> >> "Gaurhoth" <gaurhoth@live.com> wrote in message
> >> news:e8T4kp0LHHA.4376@TK2MSFTNGP03.phx.gbl...
> >> > Does anyone have an example of using .NET classes to issue a remote WMI
> >> > call with a timeout value specified? The cmdlet will hang in certain
> >> > circumstances indefinitely... which bites if you are 5 into a list of
> >> > 100
> >> > computers I haven't discovered a way to programatically
> >> > monitor/trap/break out of a hung WMI, so I'm hoping using the .NET
> >> > class
> >> > will allow me to circumvent this problem.
> >> >
> >> >
> >> > --
> >> >
> >> > gaurhoth
> >> > http://gaurhothw.spaces.live.com/
> >> >
> >> >
> >>
> >>

>
>

My System SpecsSystem Spec
Closed Thread
Update your Vista Drivers Update Your Drivers Now!!

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
server timeout beastymantis Live Folder Share 1 06-18-2008 04:12 PM
Command Timeout rob schieber .NET General 1 05-05-2008 04:43 PM
timeout functionality Frank PowerShell 7 07-31-2007 04:52 PM
Anyway to timeout a command Frank PowerShell 1 04-17-2007 03:20 AM
pipeline timeout William Stacey [C# MVP] PowerShell 0 04-09-2007 03:26 PM


Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51