Jump to content

On Error Resume Next


oleg
 Share

Recommended Posts

I got this script it lists workgroup computers .

For logical reason it fail because of some system is not accessable with same credentials .

How its possible to resume on this errors in autoit ?

------------------------------------------------------------------------------------------------------

dim $SYSNAME ,$MAC

$objDomain = ObjGet("WinNT://pvp")

$objDomain.Filter = "Array('computer')"

For $objComputer In $objDomain

$SYSNAME = $objComputer.Name&@CRLF

ConsoleWrite ( $SYSNAME )

If Not $SYSNAME = "" Then

$objLocator = ObjCreate( "WbemScripting.SWbemLocator")

$objWMIService = $objLocator.ConnectServer ($SYSNAME, "root/cimv2", $SYSNAME & "\" & $Username, $Password)

$objWMIService.Security_.impersonationlevel = 3

EndIf

$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter WHERE Name = 'NVIDIA nForce Networking Controller'")

For $bjItem In $colItems

$MAC = $bjItem.MACAddress

Next

$MAC = StringReplace ($mac,":","")

FileWriteLine ( "macs.dat",$SYSNAME&" "&$MAC)

Exit

Next

Edited by oleg

There is a hex ( 31303030303030 ) reasons i love AutoIt !

Link to comment
Share on other sites

  • Developers

use:

$oMyError = ObjEvent("AutoIt.Error", "ComError")
; Your code

Func ComError()
    If IsObj($oMyError) Then
        $HexNumber = Hex($oMyError.number, 8)
        SetError($HexNumber)
    EndIf
    Return 0
EndFunc  ;==>ComError

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

Global $SYSNAME, $MAC, $oMyError
$objDomain = ObjGet("WinNT://" & @LogonDomain)
$objDomain.Filter = "Array('computer')"
For $objComputer In $objDomain
    SetError(0)
    $SYSNAME = $objComputer.Name
    ConsoleWrite($SYSNAME & @LF)
    If Not $SYSNAME = "" Then
        Local $objLocator = ObjCreate( "WbemScripting.SWbemLocator")
        $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")   ; Initialize a COM error handler
        Local $objWMIService = $objLocator.ConnectServer ($SYSNAME, "root/cimv2", $SYSNAME & "\" & $Username, $Password)
        If Not @error Then
            $objWMIService.Security_.impersonationlevel = 3
            $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapter WHERE Name = 'NVIDIA nForce Networking Controller'")
            For $bjItem In $colItems
                $MAC = $bjItem.MACAddress
            Next
            $MAC = StringReplace($MAC, ":", "")
            FileWriteLine("macs.dat", $SYSNAME & " " & $MAC)
        EndIf
    EndIf
Next

; This is my custom defined error handler
Func MyErrFunc()
    If IsObj($oMyError) Then
        $HexNumber = Hex($oMyError.number, 8)   ; for displaying purposes
        MsgBox(0, "AutoItCOM Test", "We intercepted a COM Error !" & @CRLF & @CRLF & _
                "err.description is: " & @TAB & $oMyError.description & @CRLF & _
                "err.number is: " & @TAB & $HexNumber & @CRLF & _
                "err.scriptline is: " & @TAB & $oMyError.scriptline)
        SetError(1) ; to check for after this function returns
        $oMyError = 0
    EndIf
EndFunc  ;==>MyErrFunc

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Global $SYSNAME, $MAC, $oMyError
$objDomain = ObjGet("WinNT://" & @LogonDomain)
$objDomain.Filter = "Array('computer')"
For $objComputer In $objDomain
    SetError(0)
    $SYSNAME = $objComputer.Name
    ConsoleWrite($SYSNAME & @LF)
    If Not $SYSNAME = "" Then
        Local $objLocator = ObjCreate( "WbemScripting.SWbemLocator")
        $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")  ; Initialize a COM error handler
        Local $objWMIService = $objLocator.ConnectServer ($SYSNAME, "root/cimv2", $SYSNAME & "\" & $Username, $Password)
        If Not @error Then
            $objWMIService.Security_.impersonationlevel = 3
            $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapter WHERE Name = 'NVIDIA nForce Networking Controller'")
            For $bjItem In $colItems
                $MAC = $bjItem.MACAddress
            Next
            $MAC = StringReplace($MAC, ":", "")
            FileWriteLine("macs.dat", $SYSNAME & " " & $MAC)
        EndIf
    EndIf
Next

; This is my custom defined error handler
Func MyErrFunc()
    If IsObj($oMyError) Then
        $HexNumber = Hex($oMyError.number, 8)  ; for displaying purposes
        MsgBox(0, "AutoItCOM Test", "We intercepted a COM Error !" & @CRLF & @CRLF & _
                "err.description is: " & @TAB & $oMyError.description & @CRLF & _
                "err.number is: " & @TAB & $HexNumber & @CRLF & _
                "err.scriptline is: " & @TAB & $oMyError.scriptline)
        SetError(1); to check for after this function returns
        $oMyError = 0
    EndIf
EndFunc ;==>MyErrFunc
Finaly :lmao: my head started to hurt ;)

There is a hex ( 31303030303030 ) reasons i love AutoIt !

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