stg68 Posted May 18, 2012 Share Posted May 18, 2012 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 More sharing options...
ripdad Posted May 19, 2012 Share Posted May 19, 2012 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 More sharing options...
stg68 Posted May 19, 2012 Author Share Posted May 19, 2012 Thank you. Actually I needed if "Select" query runs more than 20 seconds then exit. Link to comment Share on other sites More sharing options...
water Posted May 19, 2012 Share Posted May 19, 2012 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 - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki  Link to comment Share on other sites More sharing options...
stg68 Posted May 19, 2012 Author Share Posted May 19, 2012 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 More sharing options...
water Posted May 19, 2012 Share Posted May 19, 2012 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 - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki  Link to comment Share on other sites More sharing options...
stg68 Posted May 19, 2012 Author Share Posted May 19, 2012 Thank you! Link to comment Share on other sites More sharing options...
ripdad Posted May 20, 2012 Share Posted May 20, 2012 (edited) 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 May 20, 2012 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 More sharing options...
stg68 Posted May 23, 2012 Author Share Posted May 23, 2012 Thank you for your help! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now