Sign in to follow this  
Followers 0

WMIservice error handling

5 posts in this topic


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!



While not $adoRs.EOF

        ping (($adoRs.Fields("computer").Value),1)
        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]
                    $adoRs.Fields("status").Value = "Available"
            $adoRs.Fields("status").Value = "Switched Off or Out of Service"


Share this post

Link to post
Share on other sites

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...


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
Live for the present,
Dream of the future,
Learn from the past.

Share this post

Link to post
Share on other sites


If you add the full code or PM me, I can do some tests.

I think I know what you are talking about.



Thanks 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.


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  
Followers 0