Jump to content

COM Errors


myk3
 Share

Recommended Posts

I am having a hard time dealing with COM errors..

I wrote a a script to pull WMI info from machines and then post these items to an excel document..

I first ping the host then if ping is good do something.

I have admin access to all the systems. So I am unclear why i am getting the error. the error always states it is the first Objget item which is the first WMI pull

Here is a copy of the code.. Like I said I have no clue where to start to deal with COM errors.

#include <Constants.au3>
#include <Array.au3>
#include <adfunctions.au3>
#include <Excel.au3>

Global $aComputers
TCPStartup()
if FileExists(@scriptdir & "\OU Systems Info.xls") Then
    FileDelete (@scriptdir & "\OU Systems Info.xls")
EndIf
$sOU = "" ;this is the distigusihed name in AD
_ADGetObjectsInOU($aComputers,$sOU,"(objectclass=computer)",2,"name,location") ;calls function in the AD.au3 to query AD
_ArrayDisplay($aComputers)
$1=1
$2=2
$out = ' '
$out1 = ' '
$type =""
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$oExcel1 = _ExcelBookNew(0)
_ExcelBookSaveAs($oExcel1, @scriptdir & "\OU Systems Info", "xls", 0, 1)
_ExcelBookClose($oExcel1, 0)
$oExcel2 = _ExcelBookOpen(@scriptdir & "\OU Systems Info.xls",0)
_ExcelWriteCell($oExcel2, "HOSTNAME",1,1);Hostname
_ExcelWriteCell($oExcel2, "MAC",1,2);MAC
_ExcelWriteCell($oExcel2, "IP",1,3);IP
_ExcelWriteCell($oExcel2, "OU",1,4);OU
_ExcelWriteCell($oExcel2, "CAMP",1,5);5 CAMP
_ExcelWriteCell($oExcel2, "ZONE",1,6);6 ZONE
_ExcelWriteCell($oExcel2, "Building Number",1,7);7 Building Number
_ExcelWriteCell($oExcel2, "Room / Bay",1,8);8 Room / Bay
_ExcelWriteCell($oExcel2, "Unit asset",1,9);9 Unit asset
_ExcelWriteCell($oExcel2, "USERNAME",1,10);Username
_ExcelWriteCell($oExcel2, "IMO",1,11);11 IMO
_ExcelWriteCell($oExcel2, "Manufacturer",1,12);Manufacturer
_ExcelWriteCell($oExcel2, "Model",1,13);Model
_ExcelWriteCell($oExcel2, "Serial Number",1,14);Serial Number
_ExcelWriteCell($oExcel2, "Desktop / Notebook",1,15);15 Desktop / Notebook 
_ExcelWriteCell($oExcel2, "CPU Speed",1,16);16 CPU Speed
_ExcelWriteCell($oExcel2, "CPU Type",1,17);17 CPU Type
_ExcelWriteCell($oExcel2, "RAM",1,18);18 RAM
_ExcelWriteCell($oExcel2, "HARD Drive",1,19);19 HARD Drive
_ExcelWriteCell($oExcel2, "Type OS",1,20);20 Type OS
_ExcelWriteCell($oExcel2, "OS Version",1,21);21 OS Version
_ExcelWriteCell($oExcel2, "DAR",1,22);22 DAR
_ExcelWriteCell($oExcel2, "PKI",1,23);23 PKI
ProgressOn("Progress", "Start Scan","")
Do
    ProgressSet(($1 / UBound($aComputers)*100),(StringFormat("%.2f", $1 / UBound($aComputers)*100)) & "% Complete","Scanning " & $1 & " of " & UBound($aComputers) & " " & $aComputers[$1][0])
$var = Ping($aComputers[$1][0])
if $var Then
    $objWMI = ObjGet("winmgmts:\\"&  $aComputers[$1][0] &"\root\CIMV2")
    $objComputer = $objWMI.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    $objSystem = $objWMI.ExecQuery("SELECT * FROM Win32_SystemEnclosure", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    $objCPU = $objWMI.ExecQuery("SELECT * FROM Win32_Processor", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    $objHDD = $objWMI.ExecQuery("SELECT * FROM Win32_diskdrive", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    $objOS = $objWMI.ExecQuery("SELECT * FROM Win32_OperatingSystem", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
If IsObj($objComputer) Then
For $objItem In $objComputer
    $user = $objItem.UserName
    if $user = "Q" & @username Then
        $user = "N/A"
    endif
    if $user = "AR" & @username Then
        $user = "N/A"
    endif
    $Model = $objItem.Model
    $RAM = $objItem.TotalPhysicalMemory
next
If IsObj($objSystem) Then
For $objItem in $objSystem
    $SN = $objItem.SerialNumber
    $Manufacturer = $objItem.Manufacturer
    $type = $objItem.ChassisTypes
next
endif
if $type[0] = 1 then
        $type = "Other"
    ElseIf $type[0] = 2 then
        $type = "Unknown"
    ElseIf $type[0] = 3 then
        $type = "Desktop"
    ElseIf $type[0] = 4 then
        $type = "Low Profile Desktop"
    ElseIf $type[0] = 5 then
        $type = "Pizza Box"
    ElseIf $type[0] = 6 then
        $type = "Mini Tower"
    ElseIf $type[0] = 7 then
        $type = "Tower"
    ElseIf $type[0] = 8 then
        $type = "Portable"
    ElseIf $type[0] = 9 then
        $type = "Laptop"
    ElseIf $type[0] = 10 then
        $type = "Notebook"
    ElseIf $type[0] = 11 then
        $type = "Hand Held"
    ElseIf $type[0] = 12 then
        $type = "Docking Station"
    ElseIf $type[0] = 13 then
        $type = "All in One"
    ElseIf $type[0] = 14 then
        $type = "Sub Notebook"
    ElseIf $type[0] = 15 then
        $type = "Space-Saving"
    ElseIf $type[0] = 16 then
        $type = "Lunch Box"
    ElseIf $type[0] = 17 then
        $type = "Main System Chassis"
    ElseIf $type[0] = 18 then
        $type = "Expansion Chassis"
    ElseIf $type[0] = 19 then
        $type = "SubChassis"
    ElseIf $type[0] = 20 then
        $type = "Bus Expansion Chassis"
    ElseIf $type[0] = 21 then
        $type = "Peripheral Chassis"
    ElseIf $type[0] = 22 then
        $type = "Storage Chassis"
    ElseIf $type[0] = 23 then
        $type = "Rack Mount Chassis"
    ElseIf $type[0] = 24 then
        $type = "Sealed-Case PC"
    Endif
EndIf
If IsObj($objCPU) Then
For $objItem in $objCPU
    $CpuSpeed = $objItem.MaxClockSpeed
    $CpuType = $objItem.Name
next
EndIf
If IsObj($objHDD) Then
For $objItem in $objHDD
    $HDDModel = $objItem.model
    $HDDSize = $objItem.size
next
EndIf

If IsObj($objOS) Then
For $objItem in $objOS
$OS = $objItem.Caption
$Ver = $objItem.Version
next
EndIf
$IP = TCPNameToIP($aComputers[$1][0])
    $nbtstat = Run(@ComSpec & " /c " & 'nbtstat -a '&  $aComputers[$1][0]  &'|find "MAC"', @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)     
    While 1
    $line = StdoutRead($nbtstat)
    If @error Then ExitLoop
    If $line <> '' Then $out &= $line & @CRLF
    Wend
    _ExcelWriteCell($oExcel2, $aComputers[$1][0],$2,1) ; 1Hostname
    $out1 = StringRegExpReplace ($out, " MAC Address = ", " ")
    $out2 = StringStripWS ($out1,8)
    _ExcelWriteCell($oExcel2, $out2, $2, 2) ;2 MAC Address
    _ExcelWriteCell($oExcel2, $IP, $2, 3);3 IP address
    _ExcelWriteCell($oExcel2, $sOU, $2, 4);4 OU
    _ExcelWriteCell($oExcel2, "AJ", $2, 5);5 CAMP
    _ExcelWriteCell($oExcel2, "2", $2, 6);6 ZONE
    _ExcelWriteCell($oExcel2, "5", $2, 7);7 Building Number
    _ExcelWriteCell($oExcel2, "1", $2, 8);8 Room / Bay
    _ExcelWriteCell($oExcel2, "N/A", $2, 9);9 Unit asset
    _ExcelWriteCell($oExcel2,$user, $2, 10) ;10 User
    _ExcelWriteCell($oExcel2, "ME", $2, 11);11 IMO
    _ExcelWriteCell($oExcel2,$Manufacturer, $2, 12);12 Make / Manufacture
    _ExcelWriteCell($oExcel2,$Model, $2, 13);13 Model
    _ExcelWriteCell($oExcel2,$SN, $2, 14);14 Asset Tag / Serial Number
    _ExcelWriteCell($oExcel2,$type, $2, 15);15 Desktop / Notebook 
    _ExcelWriteCell($oExcel2,$CpuSpeed, $2, 16);16 CPU Speed
    _ExcelWriteCell($oExcel2,$CpuType, $2, 17);17 CPU Type
    _ExcelWriteCell($oExcel2,$RAM, $2, 18);18 RAM
    _ExcelWriteCell($oExcel2,"Model: " & $HDDModel & " Size: " & $HDDSize, $2, 19);19 HARD Drive
    _ExcelWriteCell($oExcel2,$OS, $2, 20);20 Type OS
    _ExcelWriteCell($oExcel2,$Ver, $2, 21);21 OS Version
    ;22 DAR
    ;23 PKI
    _ExcelBookSaveAs($oExcel2, @scriptdir & "\OU Systems Info", "xls", 0, 1)
;~  _ExcelBookClose($oExcel2, 0)
    $out =''
    $line=''
    $user=''
    $1 += 1
    $2 += 1
    Else
    _ExcelWriteCell($oExcel2, $aComputers[$1][0],$2,1)
    _ExcelWriteCell($oExcel2, "Not Online", $2, 2)
    _ExcelWriteCell($oExcel2, "N/A", $2, 10)
    _ExcelBookSaveAs($oExcel2, @scriptdir & "\OU Systems Info", "xls", 0, 1)
;~  _ExcelBookClose($oExcel2, 0)
    $1 += 1
    $2 += 1
    endif
Until $1 = UBound($aComputers)
_ExcelBookSaveAs($oExcel2, @scriptdir & "\OU Systems Info", "xls", 0, 1)
_ExcelBookClose($oExcel2, 0)

I forgot to add.. The script runs fine for most systems it only fails on a certain few.. So say it runs the first 47 loops then throws the error.

Edited by myk3
Link to comment
Share on other sites

You can add the error handling for COM objects to get more information about com errors:

#include <Constants.au3>
#include <Array.au3>
#include <adfunctions.au3>
#include <Excel.au3>

Global $ObjError = ObjEvent("AutoIt.Error", "ObjError")
Global $aComputers
TCPStartup()
if FileExists(@scriptdir & "\OU Systems Info.xls") Then
    FileDelete (@scriptdir & "\OU Systems Info.xls")
EndIf
$sOU = "" ;this is the distigusihed name in AD
_ADGetObjectsInOU($aComputers,$sOU,"(objectclass=computer)",2,"name,location") ;calls function in the AD.au3 to query AD
_ArrayDisplay($aComputers)
$1=1
$2=2
$out = ' '
$out1 = ' '
$type =""
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$oExcel1 = _ExcelBookNew(0)
_ExcelBookSaveAs($oExcel1, @scriptdir & "\OU Systems Info", "xls", 0, 1)
_ExcelBookClose($oExcel1, 0)
$oExcel2 = _ExcelBookOpen(@scriptdir & "\OU Systems Info.xls",0)
_ExcelWriteCell($oExcel2, "HOSTNAME",1,1);Hostname
_ExcelWriteCell($oExcel2, "MAC",1,2);MAC
_ExcelWriteCell($oExcel2, "IP",1,3);IP
_ExcelWriteCell($oExcel2, "OU",1,4);OU
_ExcelWriteCell($oExcel2, "CAMP",1,5);5 CAMP
_ExcelWriteCell($oExcel2, "ZONE",1,6);6 ZONE
_ExcelWriteCell($oExcel2, "Building Number",1,7);7 Building Number
_ExcelWriteCell($oExcel2, "Room / Bay",1,8);8 Room / Bay
_ExcelWriteCell($oExcel2, "Unit asset",1,9);9 Unit asset
_ExcelWriteCell($oExcel2, "USERNAME",1,10);Username
_ExcelWriteCell($oExcel2, "IMO",1,11);11 IMO
_ExcelWriteCell($oExcel2, "Manufacturer",1,12);Manufacturer
_ExcelWriteCell($oExcel2, "Model",1,13);Model
_ExcelWriteCell($oExcel2, "Serial Number",1,14);Serial Number
_ExcelWriteCell($oExcel2, "Desktop / Notebook",1,15);15 Desktop / Notebook
_ExcelWriteCell($oExcel2, "CPU Speed",1,16);16 CPU Speed
_ExcelWriteCell($oExcel2, "CPU Type",1,17);17 CPU Type
_ExcelWriteCell($oExcel2, "RAM",1,18);18 RAM
_ExcelWriteCell($oExcel2, "HARD Drive",1,19);19 HARD Drive
_ExcelWriteCell($oExcel2, "Type OS",1,20);20 Type OS
_ExcelWriteCell($oExcel2, "OS Version",1,21);21 OS Version
_ExcelWriteCell($oExcel2, "DAR",1,22);22 DAR
_ExcelWriteCell($oExcel2, "PKI",1,23);23 PKI
ProgressOn("Progress", "Start Scan","")
Do
    ProgressSet(($1 / UBound($aComputers)*100),(StringFormat("%.2f", $1 / UBound($aComputers)*100)) & "% Complete","Scanning " & $1 & " of " & UBound($aComputers) & " " & $aComputers[$1][0])
$var = Ping($aComputers[$1][0])
if $var Then
    $objWMI = ObjGet("winmgmts:\\"&  $aComputers[$1][0] &"\root\CIMV2")
    $objComputer = $objWMI.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    $objSystem = $objWMI.ExecQuery("SELECT * FROM Win32_SystemEnclosure", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    $objCPU = $objWMI.ExecQuery("SELECT * FROM Win32_Processor", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    $objHDD = $objWMI.ExecQuery("SELECT * FROM Win32_diskdrive", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    $objOS = $objWMI.ExecQuery("SELECT * FROM Win32_OperatingSystem", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
If IsObj($objComputer) Then
For $objItem In $objComputer
    $user = $objItem.UserName
    if $user = "Q" & @username Then
        $user = "N/A"
    endif
    if $user = "AR" & @username Then
        $user = "N/A"
    endif
    $Model = $objItem.Model
    $RAM = $objItem.TotalPhysicalMemory
next
If IsObj($objSystem) Then
For $objItem in $objSystem
    $SN = $objItem.SerialNumber
    $Manufacturer = $objItem.Manufacturer
    $type = $objItem.ChassisTypes
next
endif
if $type[0] = 1 then
        $type = "Other"
    ElseIf $type[0] = 2 then
        $type = "Unknown"
    ElseIf $type[0] = 3 then
        $type = "Desktop"
    ElseIf $type[0] = 4 then
        $type = "Low Profile Desktop"
    ElseIf $type[0] = 5 then
        $type = "Pizza Box"
    ElseIf $type[0] = 6 then
        $type = "Mini Tower"
    ElseIf $type[0] = 7 then
        $type = "Tower"
    ElseIf $type[0] = 8 then
        $type = "Portable"
    ElseIf $type[0] = 9 then
        $type = "Laptop"
    ElseIf $type[0] = 10 then
        $type = "Notebook"
    ElseIf $type[0] = 11 then
        $type = "Hand Held"
    ElseIf $type[0] = 12 then
        $type = "Docking Station"
    ElseIf $type[0] = 13 then
        $type = "All in One"
    ElseIf $type[0] = 14 then
        $type = "Sub Notebook"
    ElseIf $type[0] = 15 then
        $type = "Space-Saving"
    ElseIf $type[0] = 16 then
        $type = "Lunch Box"
    ElseIf $type[0] = 17 then
        $type = "Main System Chassis"
    ElseIf $type[0] = 18 then
        $type = "Expansion Chassis"
    ElseIf $type[0] = 19 then
        $type = "SubChassis"
    ElseIf $type[0] = 20 then
        $type = "Bus Expansion Chassis"
    ElseIf $type[0] = 21 then
        $type = "Peripheral Chassis"
    ElseIf $type[0] = 22 then
        $type = "Storage Chassis"
    ElseIf $type[0] = 23 then
        $type = "Rack Mount Chassis"
    ElseIf $type[0] = 24 then
        $type = "Sealed-Case PC"
    Endif
EndIf
If IsObj($objCPU) Then
For $objItem in $objCPU
    $CpuSpeed = $objItem.MaxClockSpeed
    $CpuType = $objItem.Name
next
EndIf
If IsObj($objHDD) Then
For $objItem in $objHDD
    $HDDModel = $objItem.model
    $HDDSize = $objItem.size
next
EndIf

If IsObj($objOS) Then
For $objItem in $objOS
$OS = $objItem.Caption
$Ver = $objItem.Version
next
EndIf
$IP = TCPNameToIP($aComputers[$1][0])
    $nbtstat = Run(@ComSpec & " /c " & 'nbtstat -a '&  $aComputers[$1][0]  &'|find "MAC"', @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    While 1
    $line = StdoutRead($nbtstat)
    If @error Then ExitLoop
    If $line <> '' Then $out &= $line & @CRLF
    Wend
    _ExcelWriteCell($oExcel2, $aComputers[$1][0],$2,1) ; 1Hostname
    $out1 = StringRegExpReplace ($out, " MAC Address = ", " ")
    $out2 = StringStripWS ($out1,8)
    _ExcelWriteCell($oExcel2, $out2, $2, 2) ;2 MAC Address
    _ExcelWriteCell($oExcel2, $IP, $2, 3);3 IP address
    _ExcelWriteCell($oExcel2, $sOU, $2, 4);4 OU
    _ExcelWriteCell($oExcel2, "AJ", $2, 5);5 CAMP
    _ExcelWriteCell($oExcel2, "2", $2, 6);6 ZONE
    _ExcelWriteCell($oExcel2, "5", $2, 7);7 Building Number
    _ExcelWriteCell($oExcel2, "1", $2, 8);8 Room / Bay
    _ExcelWriteCell($oExcel2, "N/A", $2, 9);9 Unit asset
    _ExcelWriteCell($oExcel2,$user, $2, 10) ;10 User
    _ExcelWriteCell($oExcel2, "ME", $2, 11);11 IMO
    _ExcelWriteCell($oExcel2,$Manufacturer, $2, 12);12 Make / Manufacture
    _ExcelWriteCell($oExcel2,$Model, $2, 13);13 Model
    _ExcelWriteCell($oExcel2,$SN, $2, 14);14 Asset Tag / Serial Number
    _ExcelWriteCell($oExcel2,$type, $2, 15);15 Desktop / Notebook
    _ExcelWriteCell($oExcel2,$CpuSpeed, $2, 16);16 CPU Speed
    _ExcelWriteCell($oExcel2,$CpuType, $2, 17);17 CPU Type
    _ExcelWriteCell($oExcel2,$RAM, $2, 18);18 RAM
    _ExcelWriteCell($oExcel2,"Model: " & $HDDModel & " Size: " & $HDDSize, $2, 19);19 HARD Drive
    _ExcelWriteCell($oExcel2,$OS, $2, 20);20 Type OS
    _ExcelWriteCell($oExcel2,$Ver, $2, 21);21 OS Version
    ;22 DAR
    ;23 PKI
    _ExcelBookSaveAs($oExcel2, @scriptdir & "\OU Systems Info", "xls", 0, 1)
;~  _ExcelBookClose($oExcel2, 0)
    $out =''
    $line=''
    $user=''
    $1 += 1
    $2 += 1
    Else
    _ExcelWriteCell($oExcel2, $aComputers[$1][0],$2,1)
    _ExcelWriteCell($oExcel2, "Not Online", $2, 2)
    _ExcelWriteCell($oExcel2, "N/A", $2, 10)
    _ExcelBookSaveAs($oExcel2, @scriptdir & "\OU Systems Info", "xls", 0, 1)
;~  _ExcelBookClose($oExcel2, 0)
    $1 += 1
    $2 += 1
    endif
Until $1 = UBound($aComputers)
_ExcelBookSaveAs($oExcel2, @scriptdir & "\OU Systems Info", "xls", 0, 1)
_ExcelBookClose($oExcel2, 0)

Func ObjError()
  Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !"      & @CRLF  & @CRLF & _
             "err.description is: "    & @TAB & $oMyError.description    & @CRLF & _
             "err.windescription:"     & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "         & @TAB & hex($oMyError.number,8)  & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "err.scriptline is: "     & @TAB & $oMyError.scriptline     & @CRLF & _
             "err.source is: "         & @TAB & $oMyError.source         & @CRLF & _
             "err.helpfile is: "       & @TAB & $oMyError.helpfile       & @CRLF & _
             "err.helpcontext is: "    & @TAB & $oMyError.helpcontext _
            )
EndFunc   ;==>ObjError

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

You can add the error handling for COM objects to get more information about com errors:

Br,

UEZ

I get an error

Posted Image

EDIT: When looking into the ADFunctions there is a

; _ADDoError  : Error event handler for COM errors. This is global so will pick up errors from your program if you include this library

How do I launch this at error?

$oMyError = ObjEvent("AutoIt.Error", "_ADDoError") ; Install a custom error handler

;  MyErrFunc
Func _ADDoError()
    $HexNumber = Hex($oMyError.number, 8)
    
    If $HexNumber = 80020009 Then
        SetError(3)
        Return
    EndIf
    
    If $HexNumber = "8007203A" Then
        SetError(4)
        Return
    EndIf
    
    MsgBox(262144, "", "We intercepted a COM Error !" & @CRLF & _
            "Number is: " & $HexNumber & @CRLF & _
            "Windescription is: " & $oMyError.windescription & @CRLF & _
            "Script Line number is: " & $oMyError.scriptline)
    
    Select
        Case $oMyError.windescription = "Access is denied."
            $objConnection.Close ("Active Directory Provider")
            $objConnection.Open ("Active Directory Provider")
            SetError(2)
        Case 1
            SetError(1)
    EndSelect
    
EndFunc   ;==>_ADDoError

EDIT2: I think it is actually working the way is says it is supposed to.. However I have no idea how to decode the message

Posted Image

Edited by myk3
Link to comment
Share on other sites

After googleing the error I was able to determine the error had to do with the WMI repo on the remote machine.. I tried to execute wmic items locally and they failed.. I rebuilt the wmi repo and all is good again.. Thanks for the help :)

Link to comment
Share on other sites

I am constantly getting errors for different systems. Is there a way to log the error but then continue with the next item in the script???

Basically during the loop phase I am getting 2 different errors.

1. When attempting to pull the WMI info from a remote system I am unable to log in.

2. I am able to log into the remote system but the WMI repo is corrupt requiring me to rebuild it.

I have already put in a ping to see if the system is online before attempting to log in, I am an Admin on the affected system.

I understand I do not want to forget about the errors but I also want to get the rest of the info I am trying to pull from the rest of my OU..

Once the error is logged I can then go back and fix the error-ed machines.

Link to comment
Share on other sites

I noticed that you are still using the "old" active directory UDF.

The "new" UDF has a lot more functions and better error handling. For download please see my signature.

I would split your script into two parts.

Part 1:

Do all the AD related stuff. The UDF installs its own error handler if none is installed when _AD_Open() is called. The error handler is dropped when _AD_Close() is called.

This would look like:

#include <ad.au3>
_AD_Open()
_ADGetObjectsInOU()
_AD_Close()

Part 2:

Do your WMI stuff. Install your own error handler. Check the kind of error you get and decide what to do (log the error and continue, exit the script ...)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I will look into the new AD udf..

It appears I need to re-write the stuff :)

No big deal.

The function names have changed from _ADxx to _AD_xx, you have to verify the parameters (results are no longer returned byRef) and _AD_Open() is needed to open a connection to the AD.

But on the other hand the adfunctions.au3 still works.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

No big deal.

The function names have changed from _ADxx to _AD_xx, you have to verify the parameters (results are no longer returned byRef) and _AD_Open() is needed to open a connection to the AD.

But on the other hand the adfunctions.au3 still works.

No clue why but now my _ExcelBookSaveAs is now giving me errors..

Link to comment
Share on other sites

No clue why but now my _ExcelBookSaveAs is now giving me errors..

What errors do you get and what did you change in your script?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Ok I figured out the excel errors, when the script is failing it doesn't close out the excel processes..

Ok for some reason it is not populating my $aComputers array like adfunctions did.. here is my code

#include <Excel.au3>
#include <Array.au3>
#include <file.au3>
#include <ad.au3>
_AD_Open()

;****************************************************************
;~ Pull items from C4 OU
;****************************************************************
Global $aComputers
$sOU =  InputBox("OU?","What is your OU's Distinguidhed Name?","","",250,125)
If  @error then
    MsgBox(0,"Error","You have submitted and invalid OU!")
    exit
elseif $sOU = "" then
    MsgBox(0,"Error","You have submitted and invalid OU!")
    exit
endif
_AD_GetObjectsInOU($aComputers,$sOU,"(objectclass=computer)",2,"name,location") ;calls function in the AD.au3 to query AD
_ArrayDisplay($aComputers)
_AD_Close()

It doesn't even display the array..

Edited by myk3
Link to comment
Share on other sites

I am an idiot I got it

#include <Excel.au3>
#include <Array.au3>
#include <file.au3>
#include <ad.au3>
_AD_Open()
;****************************************************************
;~ Pull items from C4 OU
;****************************************************************
Global $aComputers
$sOU =  InputBox("OU?","What is your OU's Distinguidhed Name?","","",250,125)
If  @error then
    MsgBox(0,"Error","You have submitted and invalid OU!")
    exit
elseif $sOU = "" then
    MsgBox(0,"Error","You have submitted and invalid OU!")
    exit
endif
$aComputers = _AD_GetObjectsInOU($sOU,"(objectclass=computer)",2,"name,location") ;calls function in the AD.au3 to query AD
_ArrayDisplay($aComputers)
_AD_Close()
Link to comment
Share on other sites

Please replace

_AD_GetObjectsInOU($aComputers,$sOU,"(objectclass=computer)",2,"name,location")
with

$aComputers = _AD_GetObjectsInOU($sOU,"(objectclass=computer)",2,"name,location")

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

To improve performance you should always use objectcategory:

$aComputers = _AD_GetObjectsInOU($sOU,"(objectcategory=computer)",2,"name,location")

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Can you explain the objectclass vs objectcategory?

objectcategory is indexed, objectclass is not.

So when you use objectclass so scan the whole AD.

Please check this link for more information.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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