N1ck Posted February 22, 2008 Share Posted February 22, 2008 Hi I need some help with a piece of code. The code works perfectly as it is most of the time, but it needs some extra error handling! I'm getting a list of pcs from a database, pinging them then getting info from the ones which respond as being alive. This works for most of the time for the 496 pcs on my list, however if one of the pcs has crashed, it responds to the ping but does not respond to the wmi query and as a result crashes the script and fails to run the rest of the pcs. I need some error handling to prevent the script ending when the $objWMIService.ExecQuery fails, and mark the pc as "out of service". Previous posts I've seen only deal with error handling after the $objWMIService.ExecQuery and not for the command itself. If anyone has any suggestions I'd be most greatful! Thanks Nick While not $adoRs.EOF ping (($adoRs.Fields("computer").Value),1) $errorcode=@error If $errorcode = 0 Then $objWMIService = objGet("winmgmts:" & "\\" & $adoRs.Fields("computer").Value & "\root\cimv2") $colItem = $objWMIService.ExecQuery("Select * from Win32_ComputerSystem") For $objItem in $colItem If StringLen($objItem.UserName) > 1 then $username = StringSplit($objItem.UserName,"\") $adoRs.Fields("status").Value = "Logged in" $adoRs.Fields("username").Value = $username[2] Else $adoRs.Fields("status").Value = "Available" EndIf Next Else $adoRs.Fields("status").Value = "Switched Off or Out of Service" EndIf $adors.Update $adors.MoveNext WEnd Link to comment Share on other sites More sharing options...
Developers Jos Posted February 22, 2008 Developers Share Posted February 22, 2008 Did you check out the Com Event error handler described in the Helpfile ? By the way ... this is not an AutoIt3X question but a regular AutoIt3 question. moved topic... Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
ptrex Posted February 22, 2008 Share Posted February 22, 2008 @Nick If you add the full code or PM me, I can do some tests. I think I know what you are talking about. regards ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
N1ck Posted February 25, 2008 Author Share Posted February 25, 2008 @NickIf you add the full code or PM me, I can do some tests. I think I know what you are talking about.regardsptrexThanks for the offer, but I think I've managed it now.. using the standard '@error' coding I'd tried in the first place! The problem with testing is that it's hard to get the remote pcs to crash when you want them to! I've let it run over the weekend and I've got a few errors written to my logfile and the auto-it script continued to work, so I'll have to wait and see if it's sorted for good.Nick Link to comment Share on other sites More sharing options...
ptrex Posted February 25, 2008 Share Posted February 25, 2008 @N1ck Good to hear you got it sorted out. Anyhow, sharing you code doesn"t harm anyone though Some others might stil learn from it. regards ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New 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