Jump to content

WMIservice error handling


N1ck
 Share

Recommended Posts

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

  • Developers

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

@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

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.

Nick

Link to comment
Share on other sites

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