Jump to content

$objWMIService. timeout question


Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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 (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...