Jump to content
Sign in to follow this  
stg68

$objWMIService. timeout question

Recommended Posts

stg68

Is there a way to set timeout for "Select * from Win32_Processor"? e.g. 20 seconds or other?

Is there a default timeout?

Thank you for your help!

Regards

$objWMIService = objget ("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")

; Check For Processor

$Processor = $objWMIService.ExecQuery ("Select * from Win32_Processor")

For $objItem in $Processor

IniWrite("WMItest.ini", "Processor Information", "Name", StringStripWS($objItem.Name, 7))

IniWrite("WMItest.ini", "Processor Information", "Manufacturer", $objItem.Manufacturer)

IniWrite("WMItest.ini", "Processor Information", "Description", $objItem.Description)

IniWrite("WMItest.ini", "Processor Information", "Current ClockSpeed", $objItem.CurrentClockSpeed)

IniWrite("WMItest.ini", "Processor Information", "Processor L2CacheSize", $objItem.L2CacheSize)

Next

Share this post


Link to post
Share on other sites
ripdad

not sure if I understand what you mean by "timeout".

do you mean to poll it at 20 second intervals?

if so, then perhaps something like this will help...

HotKeySet('{ESC}', '_Exit')
AdlibRegister('_MyFunction', 20000);ms = 20 seconds

While 1
    Sleep(10)
WEnd

Func _MyFunction()
    Local $iniFile = @ScriptDir & '\WMItest.ini'
    Local $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
    Local $Processor = $objWMIService.ExecQuery("Select * from Win32_Processor")
    ;
    For $objItem In $Processor
        IniWrite($iniFile, "Processor Information", "Name", StringStripWS($objItem.Name, 7))
        IniWrite($iniFile, "Processor Information", "Manufacturer", $objItem.Manufacturer)
        IniWrite($iniFile, "Processor Information", "Description", $objItem.Description)
        IniWrite($iniFile, "Processor Information", "Current ClockSpeed", $objItem.CurrentClockSpeed)
        IniWrite($iniFile, "Processor Information", "Processor L2CacheSize", $objItem.L2CacheSize)
    Next
EndFunc

Func _Exit()
    AdlibUnRegister('_MyFunction')
    Exit
EndFunc

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Share this post


Link to post
Share on other sites
stg68

Thank you. Actually I needed if "Select" query runs more than 20 seconds then exit.

Share this post


Link to post
Share on other sites
water

You can't interrupt a running query.

WMI is not very fast but it shouldn't run for 20 seconds to query the processors.

Do you get any error messages when it runs for more than 20 seconds?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
stg68

I had experience when WMI repository got corrupted. So, in this case the query may hang. So, I am looking for a way to continue my script in case if this happens.

Thank you for your help!

Share this post


Link to post
Share on other sites
water

In case the WMI repository got corrupted the query will run forever? If yes then I see no way for you to cancel the query.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
stg68

Thank you!

Share this post


Link to post
Share on other sites
ripdad

WMI, to my knowledge, doesn't support an interrupt or a timeout.

There is a way. It's not very nice. Kill the service. Do so at your own risk, blah, blah.

I've had to do it several times. Mostly because I accidentally ran a function that wants to scan your entire hard drive for the rest of the day with no indication of stopping.

-EDIT-

WMI corrupt - how to reinstall/repair?

-EDIT2-

I guess I should mention that if you stop the service, you will have to kill it's spawn, a second instance.

Edited by ripdad

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Share this post


Link to post
Share on other sites
stg68

Thank you for your help!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×