deadserious Posted January 13, 2014 Posted January 13, 2014 Hello Autoit users... I'm having issues with a script that I that I created, the script gets remote system information and works great, however when a password on a remote PC is incorrect it errors out and causes the script to stop. My question is, is there a way to do a On Error Resume Next within AutoIt? Or is there something that I need to do in order for the script to continue after the error occurs? Any help would be greatly appreciated... expandcollapse popup#include <Excel.au3> Local $UserName = "Administrator" Local $Password = InputBox("Enter Password", "Please enter a Password for the remote PC.") Local $csv = FileOpen(@ScriptDir & "\Get-System-Info-ICA-FromList.csv", 1) Local $strName = FileOpen(@ScriptDir & "\Computers.txt",0) If $csv = -1 Then MsgBox(16, "Error", "Unable to open Get-System-Info-ICA-FromList.csv file to write report." & @CRLF & "Please check to see if it is already open.") Exit EndIf If $strName = -1 Then MsgBox(48, "Error", "Error Reading Computers.txt for input of computer list." & @CRLF & @CRLF & "You must have a Computers.txt File with a list of" & _ " Computers to read from in the directory where this script resides.") Exit EndIf FileWrite($csv, "Computer Name" & "," & "Vergence Version" & "," & "Citrix Version" & "," & "Manufacturer" & "," & "Model" & "," & "Operating System" & @CRLF) While 1 Local $strComputerName = FileReadLine($strName) If @error = -1 Then ExitLoop FileWrite($csv, _Get_Name() & "," & _Get_Vergence_Ver() & ", " & _Get_ICA_Ver() & "," & _Get_SystemVendor() & "," & _Get_SystemVersion() & "," & _Get_OS_Name() & @CRLF) DriveMapAdd("Z:", "\\" & $strComputerName & "\C$", 8, $strComputerName & "\" & $UserName, $Password) WEnd ; ========= Function Start ===========> Func _Get_Vergence_Ver() $Vergence = FileGetVersion("Z:\Program Files\Sentillion\Vergence Authenticator\Authenticator.exe") Return $Vergence EndFunc Func _Get_ICA_Ver() $ICA = FileGetVersion("Z:\Program Files\Citrix\ICA Client\wfica32.exe") Return $ICA EndFunc Func _Get_Name() Local $s_Text = '' $objWMILocator = ObjCreate("WbemScripting.SWbemLocator") $objWMIService = $objWMILocator.ConnectServer($strComputerName, "\root\cimv2", $strComputerName & "\" & $UserName, $Password, "", "", "&H80") $colItems = $objWMIService.ExecQuery("SELECT Name FROM Win32_ComputerSystem", "WQL", 0x30) If (IsObj($objWMIService)) Then For $objItem In $colItems Local $s_Text = $ObjItem.name Next Return String($s_Text) Else Return 0 EndIf EndFunc Func _Get_SystemVendor() Local $s_Text = '' $objWMILocator = ObjCreate("WbemScripting.SWbemLocator") $objWMIService = $objWMILocator.ConnectServer($strComputerName, "\root\cimv2", $strComputerName & "\" & $UserName, $Password, "", "", "&H80") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystemProduct", "WQL", 0x30) If (IsObj($objWMIService)) Then For $objItem In $colItems Local $s_Text = $ObjItem.Vendor Next Return String($s_Text) Else Return 0 EndIf EndFunc Func _Get_SystemVersion() Local $s_Text = '' $objWMILocator = ObjCreate("WbemScripting.SWbemLocator") $objWMIService = $objWMILocator.ConnectServer($strComputerName, "\root\cimv2", $strComputerName & "\" & $UserName, $Password, "", "", "&H80") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystemProduct", "WQL", 0x30) If (IsObj($objWMIService)) Then For $objItem In $colItems Local $s_Text = $ObjItem.Name Next Return String($s_Text) Else Return 0 EndIf EndFunc Func _Get_System_Model() Local $s_Text = '' $objWMILocator = ObjCreate("WbemScripting.SWbemLocator") $objWMIService = $objWMILocator.ConnectServer($strComputerName, "\root\cimv2", $strComputerName & "\" & $UserName, $Password, "", "", "&H80") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystemProduct", "WQL", 0x30) If (IsObj($objWMIService)) Then For $objItem In $colItems Local $s_Text = $ObjItem.Version Next Return String($s_Text) Else Return 0 EndIf EndFunc Func _Get_OS_Name() Local $s_Text = '' $objWMILocator = ObjCreate("WbemScripting.SWbemLocator") $objWMIService = $objWMILocator.ConnectServer($strComputerName, "\root\cimv2", $strComputerName & "\" & $UserName, $Password, "", "", "&H80") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_OperatingSystem", "WQL", 0x30) If (IsObj($objWMIService)) Then For $objItem In $colItems Local $s_Text = $ObjItem.Caption Next Return String($s_Text) Else Return 0 EndIf EndFunc DriveMapDel("Z:") ;=========== Function End ===========> FileClose($csv) ; Opens file once the script has finished running. $oExcelExist = FileExists(@ScriptDir & "\Get-System-Info-ICA-FromList.csv") If $oExcelExist = 1 Then _ExcelBookOpen(@ScriptDir & "\Get-System-Info-ICA-FromList.csv") EndIf If @error = 1 Then MsgBox(0, "Error!", "Unable to Open the Excel Get-System-Info-ICA-FromList.csv file at the root of the script directory.") Exit ElseIf @error = 2 Then MsgBox(0, "Error!", "Cannot Open " $oExcelExist) Exit EndIf FileClose($strName) Here is the error I receive: H:ScriptingAutoItGetSystemInfoICAGet-System-Info-ICA-FromList.au3 (51) : ==> The requested action with this object has failed.: $objWMIService = $objWMILocator.ConnectServer($strComputerName, "rootcimv2", $strComputerName & "" & $UserName, $Password, "", "", "&H80") $objWMIService = $objWMILocator.ConnectServer($strComputerName, "rootcimv2", $strComputerName & "" & $UserName, $Password, "", "", "&H80")^ ERROR >Exit code: 1 Time: 125.520
Moderators JLogan3o13 Posted January 14, 2014 Moderators Posted January 14, 2014 Have you tried simply something like this? If @error Then ;handle it EndIf Or registering a COM error handler? Search for COM Reference in the help file. Toward the bottom is an example for handling COM errors. You can use things like the .description property to give you insight as to where the command failed. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
deadserious Posted January 16, 2014 Author Posted January 16, 2014 JLogan3o13, thanks I'll look at your suggestion and let you know... thanks for the input.
SlowCoder74 Posted January 16, 2014 Posted January 16, 2014 I appreciate the way AutoIT handles errors. If a function fails, it's basically the same as "on error ... resume next". Very nice. But watch out! In some cases you may not know where a point of failure is due to AutoIT's internal error handling. So you want to use @error for critical function calls to catch those errors.
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