Jump to content

Recommended Posts

Posted

Hi Everyone,

 

I have this very confusing issue on my script where after I compiled the script and run it, it prompts me with "Vendor_6.exe has stopped working"

I got the details of the error:

Problem Even Name: APPCRASH

Fault Module Name: OLEAUT32

My program runs 2 Executable files. Vendor_6.exe and Mail_reader_v2.exe

Mail_reader_v2.exe runs smoothly while Vendor_6.exe run for some time then crash on a specific process.

I got no errors in the compiler SCITE console on both.

 

Your help on this will be greatly appreciated.

Thank you

include <OutlookEX.au3> ; Note: I removed the # in the include since our security is blocking of sharing of files.
include <Excel.au3>
include <string.au3>
include <FileConstants.au3>
include <MsgBoxConstants.au3>
include <Date.au3>
include <File.au3>
include <ImageSearch.au3>

include <IE.au3>
include <Array.au3>
include <AD.au3>
include <ButtonConstants.au3>
include <GUIConstantsEx.au3>
include <WindowsConstants.au3>

include <AutoItConstants.au3>
include <ScreenCapture.au3>




Global $oExcel, $oWorkbook, $oWorkbook1 ,$oExcel_ps
Global $xlup = -4162
Global $oExcel_2 = _Excel_Open()
Global $VM_1, $NT_1 , $FN_1 , $Email_1, $VSC_1
Global $VM_2, $NT_2 , $FN_2 , $Email_2, $VSC_2
Global $VM_3, $NT_3 , $FN_3 , $Email_3, $VSC_3
Global $latest_file, $filename, $oExcel, $oWorkbook_poc
Global $login_ids_final_lower, $login_ids_final, $string_test_3, $string_test_1, $string_test, $login_ids_final
Global $col1, $row1, $login_ids, $vendor_i
Global $body_final, $body_1, $body, $body_bp
Global $request_vm, $request_vendor
Global $oOutlook1 ;,$aOL_Item1
Global $check
Global $file_2, $file_2_read, $file_3, $sWorkbook
Global $Received_time , $EmailAddress_Sender
;============================================;
;             For Password Reset Variables   ;
;============================================;
Global $result, $user_exist , $unlock_status ,$user_expired
Global $SUserId
;Global $password = "Welcome1!"
Global $password
Global $aProperties[1][2]
Global $cn, $fname,$sname
Global $cn_final, $fname_final, $sname_final
Global $split_range,$split_range_1, $array_find, $cells_1,$cells_2,$string
;============================================;
;      For Ticketing Automation Variables    ;
;============================================;
Global $oIE2, $oIE
Global $row = 0
Global $col = 0
Global $request_id_final
Global $ticket_number
;============================================;
Global $oItem , $oItem1
Global $oOutlook = _OL_Open()
If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF", "Error creating a connection to Outlook. @error = " & @error & ", @extended = " & @extended)

;Global $aOL_Item = _OL_ItemFind($oOutlook, "RonaldJayson_paggao@comcast.com\Inbox\BP_automation", $olMail, "[UnRead]=True", "", "", "EntryID,body,Sender", "", 1)
Global $aOL_Item = _OL_ItemFind($oOutlook, "\Inbox\BP_Automation\BP Password Reset", $olMail, "[UnRead]=True", "", "", "EntryID");,body,receivedtime,senderemailaddress", "", 2)
;_ArrayDisplay($aOL_Item)
Global $oOL_Item = $oOutlook.Session.GetItemFromID($aOL_Item[1][0], Default)
    Global $oOL_Sender = $oOL_Item.Sender
   If $oOL_Sender.AddressEntryUserType = $olExchangeUserAddressEntry Or $oOL_Sender.AddressEntryUserType = $olExchangeRemoteUserAddressEntry Then
        Global $oExchangeUser = $oOL_Sender.GetExchangeUser
        ;MsgBox(0, "Mail", $oExchangeUser.PrimarySmtpAddress)
        $EmailAddress_Sender = $oExchangeUser.PrimarySmtpAddress
        ;MsgBox(0, "Mail", $EmailAddress_Sender)
   EndIf

    $oItem = _OL_ItemGet($oOutlook, $aOL_Item[1][0], Default, "body")
    $oItem1 = _OL_ItemGet($oOutlook, $aOL_Item[1][0], Default, "receivedtime")


local $itime1 = $oItem1[1][1]
local $itime_1 = stringright($itime1,6)
local $itime_2 = stringregexpreplace($itime_1,'(.{2})(?!$)','$1:'); & @CRLF)
local $iyear_1 = stringleft($itime1,4)
local $idate_1 = StringTrimLeft($itime1,4)
local $idate_2 = StringTrimRight($idate_1,6)
local $fdate_1 = stringregexpreplace($idate_2,'(.{2})(?!$)','$1/'); & @CRLF)

$Received_time = $fdate_1 & "/" & $iyear_1 & " " & $itime_2
;MsgBox(0,"",$Received_time)

$body_bp = _ArrayToString($oItem," ",1,1," ",1,1) ; body
;MsgBox(0,"",$body_bp)

;$body_1 = StringRegExpReplace($body, "\r\n|\r|\n", " ")
$request_vendor = StringInStr($body_bp,"Vendor",0,1)

$request_vm = StringInStr($body_bp,"VM",0,1)

;MsgBox(0,"","FTE: " & $request_fte & @CRLF & "BP: " & $request_bp)

If $request_vendor <> 0 Then
  ; _OL_ItemMove($oOutlook, $aOL_Item[1][0], Default, "RonaldJayson_paggao@comcast.com\Inbox\BP_automation\BP Password Reset")
   ;$VM_3, $NT_3 , $FN_3 , $Email_3, $VSC_3
   _vendor()
   _range_finder($VM_3,$NT_3, $FN_3, $Email_3, $VSC_3)

ElseIf $request_vm <> 0 Then
   _vm()
   _range_finder_vm($NT_3, $FN_3, $Email_3, $VSC_3)
   ;MsgBox(0,"","For VM process")

EndIf

;_OL_Close(ByRef $oOL, $bOL_ForceClose = False)
;_OL_Close($oOutlook, False)

Func _Vendor()


$VM_1 = _StringBetween($body_bp,"Vendor name","NT Login")
;_ArrayDisplay($VM_1)
$VM_2 = _ArrayToString($VM_1,"",0,0,"",0,0)
$VM_3 = StringStripWS($VM_2,8)
;MsgBox(0,"Vendor name: ",$VM_3)

$NT_1 = _StringBetween($body_bp,"NT Login","Full Name")
;_ArrayDisplay($NT_1)
$NT_2 = _ArrayToString($NT_1,"",0,0,"",0,0)
$NT_3 = StringLower(StringStripWS($NT_2,8))
;MsgBox(0,"NT Login: ",$NT_3)

$FN_1 = _StringBetween($body_bp,"Full Name","Email Address")
;_ArrayDisplay($FN_1)
$FN_2 = _ArrayToString($FN_1,"",0,0,"",0,0)
$FN_3 = StringStripWS($FN_2,3)
;MsgBox(0,"Full Name: ",$FN_3)

$Email_1 = _StringBetween($body_bp,"Email Address","Vendor Security Code")
;_ArrayDisplay($Email_1)
$Email_2 = _ArrayToString($Email_1,"",0,0,"",0,0)
;$Email_3 = StringStripWS($Email_2,3)
;MsgBox(0,"Email: ",$Email_2)
if StringInStr($Email_2,"<") = 0 Then
   $Email_3 = StringStripWS($Email_2,3)
   ;MsgBox(0,"Email 1",$Email_3)
Else
   local $Email_3i = StringSplit($Email_2, " ",2)
   ;_ArrayDisplay($Email_3i,"Email")
   local $Email_3ii = _ArrayToString($Email_3i,"",0,0,"",0,0)
   $Email_3 = StringStripWS($Email_3ii,3)
   ;MsgBox(0,"",$Email_3)

EndIf

$VSC_1 = _StringBetween($body_bp,"Vendor Security Code","Tool")
;_ArrayDisplay($VSC_1)
$VSC_2 = _ArrayToString($VSC_1,"",0,0,"",0,0)
$VSC_3 = StringStripWS($VSC_2,8)
;MsgBox(0,"Vendor Security Code: ",$VSC_3)

EndFunc

Func _VM()

$NT_1 = _StringBetween($body_bp,"NT Login","Full Name")
;_ArrayDisplay($NT_1)
$NT_2 = _ArrayToString($NT_1,"",0,0,"",0,0)
$NT_3 = StringLower(StringStripWS($NT_2,8))
;MsgBox(0,"NT Login: ",$NT_3)

$FN_1 = _StringBetween($body_bp,"Full Name","Email Address")
;_ArrayDisplay($FN_1)
$FN_2 = _ArrayToString($FN_1,"",0,0,"",0,0)
$FN_3 = StringStripWS($FN_2,3)
;MsgBox(0,"Full Name: ",$FN_3)

$Email_1 = _StringBetween($body_bp,"Email Address","Phone Number")
;_ArrayDisplay($Email_1)
$Email_2 = _ArrayToString($Email_1,"",0,0,"",0,0)
;$Email_3 = StringStripWS($Email_2,3)
;MsgBox(0,"Email: ",$Email_2)
if StringInStr($Email_2,"<") = 0 Then
   $Email_3 = StringStripWS($Email_2,3)
   ;MsgBox(0,"Email 1",$Email_3)
Else
   local $Email_3i = StringSplit($Email_2, " ",2)
   ;_ArrayDisplay($Email_3i,"Email")
   local $Email_3ii = _ArrayToString($Email_3i,"",0,0,"",0,0)
   $Email_3 = StringStripWS($Email_3ii,3)
   ;MsgBox(0,"",$Email_3)

EndIf

$VSC_1 = _StringBetween($body_bp,"Phone Number","Tool")
;_ArrayDisplay($VSC_1)
$VSC_2 = _ArrayToString($VSC_1,"",0,0,"",0,0)
$VSC_3 = StringStripWS($VSC_2,8)
;MsgBox(0,"Vendor Security Code: ",$VSC_3)

EndFunc

Func _process_1()

If FileExists(@scriptdir & "\test.txt") = 1 Then
   FileDelete(@scriptdir & "\test.txt")
   _OL_ItemExport(@ScriptDir & "\test.txt", " ", "", 1, "Subject,Body", $oItem) ;"Subject,Start,End,Body"

    $file_2 = FileOpen(@scriptdir & "\test.txt",0)
    $file_2_read = FileRead($file_2)
   ;MsgBox(0,"",$file_2_read)
                  If FileExists(@scriptdir & "\test.xlsx") = 0 Then
                                ;_Excel_BookOpenText($oExcel, $sTextFile, Default, $xlDelimited, Default, True, "|", $aFieldInfo, ",", ".")
                                $oWorkbook = _Excel_BookOpenText($oExcel_2, @scriptdir & "\test.txt", Default, $xlDelimited, Default, True)
                                 If @error Then
                                   MsgBox(0,"Excel Error: ",@error)
                                 EndIf
                                $sWorkbook = @ScriptDir & "\test.xlsx"
                                _Excel_BookSaveAs($oWorkbook, $sWorkbook, Default, True)
                                _Excel_BookClose($oWorkbook,true)
                                _Excel_Close ($oExcel_2 ,True)
                                 ;MsgBox(0,"","excel")
                                FileClose($file_2)
                                if ProcessExists("EXCEL.EXE") Then ProcessClose("EXCEL.EXE")
                                 ;MsgBox(0,"","Done",3)
                  Else
                                FileDelete(@scriptdir & "\test.xlsx")
                                $oWorkbook = _Excel_BookOpenText($oExcel_2, @scriptdir & "\test.txt", Default, $xlDelimited, Default, True)
                                 If @error Then
                                   MsgBox(0,"Excel Error: ",@error)
                                 EndIf
                                $sWorkbook = @ScriptDir & "\test.xlsx"
                                _Excel_BookSaveAs($oWorkbook, $sWorkbook, Default, True)
                                _Excel_BookClose($oWorkbook,true)
                                _Excel_Close ($oExcel_2 ,True)
                                FileClose($file_2)
                                if ProcessExists("EXCEL.EXE") Then ProcessClose("EXCEL.EXE")
                  EndIf
Else
   _OL_ItemExport(@ScriptDir & "\test.txt", " ", "", 1, "Subject,Body", $aOL_Item) ;"Subject,Start,End,Body"
    $file_2 = FileOpen(@scriptdir & "\test.txt",0)
    $file_2_read = FileRead($file_2)
                  If FileExists(@scriptdir & "\test.xlsx") = 0 Then
                                  $oWorkbook = _Excel_BookOpenText($oExcel_2, @scriptdir & "\test.txt", Default, $xlDelimited, Default, True)
                                 If @error Then
                                   MsgBox(0,"Excel Error: ",@error)
                                 EndIf
                                  $sWorkbook = @ScriptDir & "\test.xlsx"
                                  _Excel_BookSaveAs($oWorkbook, $sWorkbook, Default, True)
                                  _Excel_BookClose($oWorkbook,true)
                                  _Excel_Close ($oExcel_2 ,True)
                                FileClose($file_2)
                                if ProcessExists("EXCEL.EXE") Then ProcessClose("EXCEL.EXE")
                  Else
                                FileDelete(@scriptdir & "\test.xlsx")
                                $oWorkbook = _Excel_BookOpenText($oExcel_2, @scriptdir & "\test.txt", Default, $xlDelimited, Default, True)
                                 If @error Then
                                   MsgBox(0,"Excel Error: ",@error)
                                 EndIf
                               $sWorkbook = @ScriptDir & "\test.xlsx"
                                _Excel_BookSaveAs($oWorkbook, $sWorkbook, Default, True)
                                _Excel_BookClose($oWorkbook,true)
                                _Excel_Close ($oExcel_2 ,True)
                                FileClose($file_2)
                                if ProcessExists("EXCEL.EXE") Then ProcessClose("EXCEL.EXE")
                  EndIf

EndIf

$string = "NT LOGIN"

$oExcel = _Excel_Open()
;MsgBox(0,"","test")

$oWorkbook1 = _Excel_BookOpen($oExcel, @ScriptDir & "\Test.xlsx" , false, True)

$array_find = _Excel_RangeFind($oWorkbook1, $string, "A:A", Default, $xlPart, False)
;_ArrayDisplay($array_find)
$rows_1 = UBound($array_find,1)
;MsgBox(0,"row: " , $rows_1)
$columns_1 = UBound($array_find,2)
;MsgBox(0,"col: " , $columns_1)
$split_range = _ArrayToString($array_find, "",0,$rows_1-1,@lf,2,2)
;MsgBox(0,"",$split_range)
$split_range_1 = StringSplit($split_range,@crlf)
;_arraydisplay($split_range_1)
For $i = 1 to $split_range_1[0]
   ;MsgBox(0,"",$split_range_1[$i])
    $cells_1 = StringReplace($split_range_1[$i],"$A$","",0,0)
    $cells_2 = _Excel_RangeRead($oWorkbook1,$oWorkbook1.activesheet,"A" & $cells_1+2, Default)
   ;MsgBox(0,"",$cells_1)
   ;#cs

   local $letter = "B"
   local $number = "0"
   local $cell = $letter & $number

   $value = _Excel_RangeRead($oWorkbook1,$oWorkbook1.activesheet,$letter & $number, Default)

   While $value <> "" or $value <> null or $value <> " "
      $number = $number + 1
      $value1 = _Excel_RangeRead($oWorkbook1,$oWorkbook1.activesheet,$letter & $number, Default)

      If $value1 = "" or $value1 = " " or $value1 = null Then

         _Excel_RangeWrite($oWorkbook1, $oWorkbook1.activesheet, StringStripWS((stringlower($cells_2)),8), "B" & $number,false,false)

         ExitLoop
      EndIf
   WEnd

Next
         _Excel_RangeDelete ($oWorkbook1.activesheet, "B1" ,Default, 1)
         _Excel_BookSave($oWorkbook1)
         _Excel_Close($oExcel)

_main_password_reset()


EndFunc

Func _FindLatest($dir)
    Local $latest[2]
    $files = _FileListToArray($dir, "Master List Business Partner Access POCs LOGINS with Vendor Security Codes *", 1)
    For $i = 1 To UBound($files) - 1
        If FileGetTime($files[$i], 1, 1) > $latest[0] Or $i = 1 Then
            $latest[0] = FileGetTime($files[$i], 1, 1)
            $latest[1] = $i
        EndIf
    Next
    Return $files[$latest[1]]
 EndFunc  ;==>_FindLatest

Func _range_finder($vendor_i,$nt_login_i, $fname_i, $email_i, $v_security_i)

$latest_file = _FindLatest("\\Path\") ; I removed the path due to confidentiality
;MsgBox(0,"",$latest_file)
$filename = "\\Path\" & $latest_file ; I removed the path due to confidentiality

$oExcel_poc = _Excel_Open()
;$oExcel.WorkBooks.Open($FileName, Default, 0, Default, $sPassword, Default)
$oWorkbook_poc = _Excel_BookOpen($oExcel_poc, $filename , true, True,"Safety",Default)
If WinExists("Microsoft Excel","") = 1 Then
   ControlClick("Microsoft Excel","Close the program","Button2","left",1)
EndIf
If @error Then
   MsgBox($MB_systemmodal, "Excel UDF","Error Opening Workbook",2)
   _Excel_Close($oExcel_poc)
   ShellExecute(@scriptdir & "\Excel_error_handling.exe",1)
   Exit
EndIf

$Vendor = _Excel_RangeFind($oWorkbook_poc, $vendor_i , "A:A",Default,$xlpart, Default)
;_ArrayDisplay($Vendor)

$NT_login = _Excel_RangeFind($oWorkbook_poc, $nt_login_i , "E:E",Default,$xlpart, Default)
;_ArrayDisplay($NT_login)

$fname_v = _Excel_RangeFind($oWorkbook_poc, $fname_i , "B:B",Default,$xlpart, Default)
;_ArrayDisplay($fname_v)

$email_v = _Excel_RangeFind($oWorkbook_poc, $email_i, "C:C",Default,$xlpart, Default)
;_ArrayDisplay($email_v)

$v_security = _Excel_RangeFind($oWorkbook_poc, $v_security_i, "F:F",Default,$xlpart, Default)
;_ArrayDisplay($v_security)

If Ubound($Vendor) > 0 and Ubound($NT_login) > 0 and Ubound($fname_v) > 0 and Ubound($email_v) > 0 and Ubound($v_security) > 0 Then
   MsgBox(16,"Status: ", "Validation success",1)
   _process_1()
ElseIf Ubound($Vendor) <= 0 Then
   MsgBox(16,"Status: ", "Validation Failed , Invalid Vendor Name")
   _OL_ItemMove($oOutlook, $aOL_Item[1][0], Default, "\Inbox\BP_automation\BP_Fallout")
   log_invalid_vendor_name()
   Exit
ElseIf Ubound($NT_login) <= 0 Then
   MsgBox(16,"Status: ", "Validation Failed , Invalid NT Login")
   _OL_ItemMove($oOutlook, $aOL_Item[1][0], Default, "\Inbox\BP_automation\BP_Fallout") ; removed my mailbox name for confidentiality
   log_invalid_NT_ID()
   Exit
ElseIf Ubound($fname_v) <= 0 Then
   MsgBox(16,"Status: ", "Validation Failed , Invalid Full Name")
   _OL_ItemMove($oOutlook, $aOL_Item[1][0], Default, "\Inbox\BP_automation\BP_Fallout") ; removed my mailbox name for confidentiality
   log_invalid_Fname()
ElseIf Ubound($email_v) <= 0 Then
   MsgBox(16,"Status: ", "Validation Failed , Invalid Email Address")
   _OL_ItemMove($oOutlook, $aOL_Item[1][0], Default, "\Inbox\BP_automation\BP_Fallout") ; removed my mailbox name for confidentiality
   log_invalid_Email()
   Exit
ElseIf Ubound($v_security) <= 0 Then
   MsgBox(16,"Status: ", "Validation Failed , Invalid Security Code")
   _OL_ItemMove($oOutlook, $aOL_Item[1][0], Default, "\Inbox\BP_automation\BP_Fallout") ; removed my mailbox name for confidentiality
   log_invalid_security_code()
   Exit
;Else
;   MsgBox(16,"Status: ", "Validation failed")
;    _OL_ItemMove($oOutlook, $aOL_Item[1][0], Default, "RonaldJayson_paggao@comcast.com\Inbox\BP_automation\BP_Fallout")
    ;Email Script
EndIf

EndFunc


Func _range_finder_vm($nt_login_i, $fname_i, $email_i, $v_security_i)

$latest_file = _FindLatest("\\Path\"); I removed the path due to confidentiality
;MsgBox(0,"",$latest_file)
$filename = "\\Path\" & $latest_file ; I removed the path due to confidentiality

$oExcel_poc = _Excel_Open()
;$oExcel.WorkBooks.Open($FileName, Default, 0, Default, $sPassword, Default)
$oWorkbook_poc = _Excel_BookOpen($oExcel_poc, $filename , true, True,"Safety",Default)
If WinExists("Microsoft Excel","") = 1 Then
   ControlClick("Microsoft Excel","Close the program","Button2","left",1)
EndIf
If @error Then
   MsgBox($MB_systemmodal, "Excel UDF","Error Opening Workbook",2)
   _Excel_Close($oExcel_poc)
   ShellExecute(@scriptdir & "\Excel_error_handling.exe",1)
   Exit
EndIf

$NT_login = _Excel_RangeFind($oWorkbook_poc, $nt_login_i , "E:E",Default,$xlpart, Default)
;_ArrayDisplay($NT_login)

$fname_v = _Excel_RangeFind($oWorkbook_poc, $fname_i , "B:B",Default,$xlpart, Default)
;_ArrayDisplay($fname_v)

$email_v = _Excel_RangeFind($oWorkbook_poc, $email_i, "C:C",Default,$xlpart, Default)
;_ArrayDisplay($email_v)

$v_security = _Excel_RangeFind($oWorkbook_poc, $v_security_i, "D:D",Default,$xlpart, Default)
;_ArrayDisplay($v_security)

;If Ubound($Vendor) > 0

If Ubound($NT_login) > 0 and Ubound($fname_v) > 0 and Ubound($email_v) > 0 and Ubound($v_security) > 0 Then
   MsgBox(16,"Status: ", "Validation success",1)
   _process_1()

ElseIf Ubound($NT_login) <= 0 Then
   MsgBox(16,"Status: ", "Validation Failed , Invalid NT Login",1)
   _OL_ItemMove($oOutlook, $aOL_Item[1][0], Default, "\Inbox\BP_automation\BP_Fallout") ; removed my mailbox name for confidentiality
   log_invalid_NT_ID()
   Exit
ElseIf Ubound($fname_v) <= 0 Then
   MsgBox(16,"Status: ", "Validation Failed , Invalid Full Name",1)
   _OL_ItemMove($oOutlook, $aOL_Item[1][0], Default, "\Inbox\BP_automation\BP_Fallout") ; removed my mailbox name for confidentiality
   log_invalid_Fname()
   Exit
ElseIf Ubound($email_v) <= 0 Then
   MsgBox(16,"Status: ", "Validation Failed , Invalid Email Address",1)
   _OL_ItemMove($oOutlook, $aOL_Item[1][0], Default, "\Inbox\BP_automation\BP_Fallout") ; removed my mailbox name for confidentiality
   log_invalid_Email()
   Exit
ElseIf Ubound($v_security) <= 0 Then
   MsgBox(16,"Status: ", "Validation Failed , Invalid Phone Number",1)
   _OL_ItemMove($oOutlook, $aOL_Item[1][0], Default, "\Inbox\BP_automation\BP_Fallout") ; removed my mailbox name for confidentiality
   log_invalid_phone()
   Exit
;Else
;   MsgBox(16,"Status: ", "Validation failed")
;    _OL_ItemMove($oOutlook, $aOL_Item[1][0], Default, "RonaldJayson_paggao@comcast.com\Inbox\BP_automation\BP_Fallout")
    ;Email Script
EndIf

EndFunc

;=====================================================;
;=============== For Password Reset ==================;
;=====================================================;

Func _main_password_reset()

  ;$password = "Welcome1!";MakePass() ; Password Generator
   ;MsgBox(0,"completed password: ", $text)
   _readexcel()

EndFunc


Func _readexcel()

While 1

$oExcel_ps = _Excel_Open()
$oWorkbook = _Excel_BookOpen($oExcel_ps, @ScriptDir & "\Test.xlsx", Default, True)
Sleep(1000)
$oWorkbook.activate
;$lastrow = $oWorkbook.ActiveSheet.Range("B1").SpecialCells($xlCellTypeLastCell).Row
$lastrow = $oWorkbook.ActiveSheet.range("B65536").end($xlup).row

$first = $lastrow

$nameofrequester = _Excel_RangeRead($oWorkbook, 2, "B3", 1)
$emailofrequester = _Excel_RangeRead($oWorkbook, 2, "B4", 1)
;MsgBox(0,'Name of Requestor',$nameofrequestor, 5)

local $plusone = 0
local $emailplusone = 0

local $i = 1

For $i = 1 to $first

      $plusone = $plusone + 1
      $xplusone = "B" & $plusone
      ;MsgBox(0,"",$xplusone)
      sleep(1000)
      ;$oWorkbook.activate
      $SUserId = StringLower(_Excel_RangeRead($oWorkbook, 1, $xplusone, 3))
      MsgBox(0,"NTlogin",$SUserId,3)

      $password = MakePass();"Welcome1!";place the funciton of password generator

      _AD_process()
      Sleep(3000)
      _login2();For ticketing function
      MsgBox(0,"Status","Ticketing Completed",3)
      ;_OL_ItemMove($oOutlook, $aOL_Item[1][0], Default, "RonaldJayson_paggao@comcast.com\Inbox\BP_automation\BP Completed")

Sleep(1000)



Next

Sleep(4000)
_email_successful(); Email successful list
 _OL_ItemMove($oOutlook, $aOL_Item[1][0], Default, "\Inbox\BP_automation\BP Completed") ; removed my mailbox name for confidentiality
 _Refresh_BP_Success_logs()
 ;$oExcel_ps
 _Excel_BookClose($oWorkbook, True)
 _Excel_Close($oExcel_ps,false)

ExitLoop

WEnd

EndFunc


Func _AD_process()

_AD_Open()
If @error Then Exit MsgBox(16, "Active Directory Example Skript", "Function _AD_Open encountered a problem. @error = " & @error & ", @extended = " & @extended,3)

$aProperties = _AD_GetObjectProperties($SUserId,"cn,givenName,sn")

$cn = _ArrayToString($aProperties,"",1,1,"",1,1) ; cn
;MsgBox(0,"",$cn)
$fname = _ArrayToString($aProperties,"",2,2,"",1,1) ; fname
;MsgBox(0,"",$fname)
$sname = _ArrayToString($aProperties,"",4,4,"",1,1) ; sname
;MsgBox(0,"",$sname)

$cn_final = StringStripWS($cn,8)
;MsgBox(0,"",$cn_final)
$fname_final = StringStripWS($fname,8)
;MsgBox(0,"",$fname_final)
$sname_final = StringStripWS($sname,8)
;MsgBox(0,"",$sname_final)

$user_exist = _AD_ObjectExists($SUserId,"")
$user_expired = _AD_IsPasswordExpired($SUserId)

If $user_exist = 1 Then
   MsgBox(64, "Active Directory Functions ", "User Exists",2)
   If $user_expired = 0 Then
      MsgBox(64, "Active Directory Functions", "User account '" & $SUserId & "' is not expired",2)
         If _AD_IsObjectLocked($SUserId) = 1 Then
            MsgBox(64, "Active Directory Functions", "User account '" & $SUserId & "' is locked",2)
               $unlock_status = _AD_UnlockObject($SUserId)
                  If $unlock_status = 1 Then
                     MsgBox(64, "Active Directory Functions ", "Object '" & $SUserId & "' successfully Unlocked",2)
                     $result = _AD_SetPassword($SUserId, $password,0)
                     If $result = 1 Then
                        MsgBox(64, "Active Directory Functions ", "Password for the current user successfully changed",2)
                        _AD_DisablePasswordChange($SUserId)
                        log_unlocked_and_reset() ;FOR unlocked and reset logs
                     ElseIf @error = 1 Then
                        MsgBox(16, "Active Directory Functions ", "Error occurred when accessing the current user object!" & @LF & "@error = " & @error & ", @extended = " & @extended,2)
                     Else
                        MsgBox(16, "Active Directory Functions ", "Error occurred when changing the password!" & @LF & "@error = " & @error & ", @extended = " & @extended,2)
                     EndIf
                  Else
                     MsgBox(64, "Active Directory Functions ", "Object '" & $SUserId & "' Unable to unlock",2)
                     log_unable_to_unlock() ;FOR unable to unlock ID logs
                  EndIf
            Else
               MsgBox(64, "Active Directory Functions ", "Object '" & $SUserId & "' is not locked",2)
               $result = _AD_SetPassword($SUserId, $password,0)
                  If $result = 1 Then
                     MsgBox(64, "Active Directory Functions ", "Password for the current user successfully changed",2)
                     _AD_DisablePasswordChange($SUserId)
                     log_reset_only() ;FOR reset only logs
                  ElseIf @error = 1 Then
                     MsgBox(16, "Active Directory Functions ", "Error occurred when accessing the current user object!" & @LF & "@error = " & @error & ", @extended = " & @extended,2)
                  Else
                     MsgBox(16, "Active Directory Functions ", "Error occurred when changing the password!" & @LF & "@error = " & @error & ", @extended = " & @extended,2)
                  EndIf
            EndIf
   Else
      MsgBox(64, "Active Directory Functions ", "Object '" & $SUserId & "' Already Expired",2)
      log_expired() ;FOR Expired ID logs
   EndIf
Else
   MsgBox(64, "Active Directory Functions ", "Object '" & $SUserId & "' Does not exist",3)
   log_user_not_found()
EndIf
; Close Connection to the Active Directory
_AD_Close()


EndFunc

Func MakePass()
; verify that password will have at least 1 of all three types of chars
    $GoodPass = 0
    Do
        $chkPass = rndLayout()
        If StringInStr($chkPass, "1") Then
            If StringInStr($chkPass, "2") Then
                If StringInStr($chkPass, "3") Then
                    $GoodPass = 1
                EndIf
            EndIf
        EndIf
    Until $GoodPass = 1

; Now that we have an acceptable layout for the password... populate it
    $password = ""
    For $x = 1 To 8
        $password = $password & Convert(StringMid($chkPass, $x, 1))
                                ;MsgBox(0,"password convert: ", $password)
                Next
                                ;MsgBox(0,"Final Password: ", $password)
    ClipPut($password)
    Return $password
EndFunc  ;==>MakePass

Func Convert($cat)
   ; Numbers
    If $cat = 1 Then
        $val = Chr(Random(49, 57, 1))
                                ;MsgBox(0,"Converted value: ",$val)
    ; Capital Letters
    ElseIf $cat = 2 Then
        $val = Chr(Random(65, 90, 1))
                                ;MsgBox(0,"Converted value: ",$val)
    ; Lowercase Letters
    Else
        $val = Chr(Random(97, 122, 1))
                                ;MsgBox(0,"Converted value: ",$val)
    EndIf

; Subsitute undesired values to other values (personal preference)
    If $val = "l" Then $val = "x"
    If $val = "1" Then $val = "5"
    If $val = "i" Then $val = "y"
    If $val = "O" Then $val = "R"

    Return $val
EndFunc  ;==>Convert

; make a 7 char string of numbers 1 thru 3
Func rndLayout()
    $str = ""
    For $i = 1 To 7
        $str = $str & Random(1, 3, 1)
    Next
    Return $str
                ;MsgBox(0,"Password String: " ,$str)
EndFunc  ;==>rndLayout


;=========================================================================
;=================== Logs Functions Successful Validation ================
;=========================================================================

Func log_expired() ;FOR Expired ID

 $oExcel3 = _Excel_Open()

If WinExists("Microsoft Excel","") = 1 Then
   ControlClick("Microsoft Excel","Close the program","Button2","left",1)
EndIf

$oWorkbook2 = _Excel_BookOpen($oExcel3, @ScriptDir & "\log_bp_pw.xlsx", Default, True)
$oWorkbook2.Sheets("Processed").Activate
;_Excel_RangeDelete ( $oWorksheet, $vRange [, $iShift = Default [, $iEntireRowCol = Default]] )
$oRange = $oWorkbook2.ActiveSheet.range("A2").SpecialCells($xlCellTypeLastCell).row
;MsgBox(0,"",$oRange)

Sleep(1000)

_Excel_RangeInsert($oWorkbook2.Activesheet, "A2:G2", $xlShiftDown , 1);Default)
_Excel_RangeWrite($oWorkbook2, Default,$SUserId,"A2")
_Excel_RangeWrite($oWorkbook2, Default,$Received_time,"B2")
_Excel_RangeWrite($oWorkbook2, Default, _NowTime(3), "C2")
_Excel_RangeWrite($oWorkbook2, Default, "Expired ID", "D2")
_Excel_RangeWrite($oWorkbook2, Default, $FN_3, "E2")
_Excel_RangeWrite($oWorkbook2, Default, $EmailAddress_Sender, "F2") ;$EmailAddress_Sender ; $Email_3
;_Excel_RangeWrite($oWorkbook2, Default, $EmailAddress_Sender, "G2") ;
$oWorkbook2.ActiveSheet.Columns("A:G").AutoFit
$oExcel3.ActiveSheet.Columns("A:G").HorizontalAlignment = $xlLeft ; Can be xlCenter, xlDistributed, xlJustify, xlLeft or xlRight of the XlHAlign enumeration.
$oExcel3.ActiveSheet.usedrange.Borders.LineStyle = 1
_Excel_BookClose($oWorkbook2, True)
_Excel_Close($oExcel3,false)

$oExcel3 = _Excel_Open()

If WinExists("Microsoft Excel","") = 1 Then
   ControlClick("Microsoft Excel","Close the program","Button2","left",1)
EndIf

$oWorkbook2 = _Excel_BookOpen($oExcel3, @ScriptDir & "\BP_Success.xlsx", Default, True)
$oWorkbook2.Sheets("Processed").Activate
;_Excel_RangeDelete ( $oWorksheet, $vRange [, $iShift = Default [, $iEntireRowCol = Default]] )
$oRange = $oWorkbook2.ActiveSheet.range("A2").SpecialCells($xlCellTypeLastCell).row
;MsgBox(0,"",$oRange)

Sleep(1000)

_Excel_RangeInsert($oWorkbook2.Activesheet, "A2:F2", $xlShiftDown , 1);Default)
_Excel_RangeWrite($oWorkbook2, Default,"NT LOGIN","A2")
_Excel_RangeWrite($oWorkbook2, Default,$SUserId,"B2")
_Excel_RangeWrite($oWorkbook2, Default, $fname, "C2")
_Excel_RangeWrite($oWorkbook2, Default, $sname, "D2")
_Excel_RangeWrite($oWorkbook2, Default, "N/A", "E2")
_Excel_RangeWrite($oWorkbook2, Default, "Expired ID", "F2") ;$EmailAddress_Sender ; $Email_3
;_Excel_RangeWrite($oWorkbook2, Default, $EmailAddress_Sender, "G2") ;
$oWorkbook2.ActiveSheet.Columns("A:F").AutoFit
$oExcel3.ActiveSheet.Columns("A:F").HorizontalAlignment = $xlLeft ; Can be xlCenter, xlDistributed, xlJustify, xlLeft or xlRight of the XlHAlign enumeration.
$oExcel3.ActiveSheet.usedrange.Borders.LineStyle = 1
_Excel_BookClose($oWorkbook2, True)
_Excel_Close($oExcel3,false)

EndFunc

Func _Refresh_BP_Success_logs()

   $oExcel3 = _Excel_Open()

If WinExists("Microsoft Excel","") = 1 Then
   ControlClick("Microsoft Excel","Close the program","Button2","left",1)
EndIf

$oWorkbook2 = _Excel_BookOpen($oExcel3, @ScriptDir & "\BP_Success.xlsx", Default, True)
$oWorkbook2.Sheets("Processed").Activate
;_Excel_RangeDelete ( $oWorksheet, $vRange [, $iShift = Default [, $iEntireRowCol = Default]] )
$oRange = $oWorkbook2.ActiveSheet.range("A2").SpecialCells($xlCellTypeLastCell).row
;MsgBox(0,"",$oRange)
If $oRange > 1 then
_Excel_RangeDelete ($oWorkbook2.activesheet,"A2" &":E"&$oRange  , Default ,  Default)
EndIf
;if @error Then MsgBox(0,"",@error)


_Excel_BookClose($oWorkbook2, True)
_Excel_Close($oExcel3,false)

EndFunc

Func log_unable_to_unlock();FOR unable to unlock ID


 $oExcel3 = _Excel_Open()

If WinExists("Microsoft Excel","") = 1 Then
   ControlClick("Microsoft Excel","Close the program","Button2","left",1)
EndIf

$oWorkbook2 = _Excel_BookOpen($oExcel3, @ScriptDir & "\log_bp_pw.xlsx", Default, True)
$oWorkbook2.Sheets("Processed").Activate
;_Excel_RangeDelete ( $oWorksheet, $vRange [, $iShift = Default [, $iEntireRowCol = Default]] )
$oRange = $oWorkbook2.ActiveSheet.range("A2").SpecialCells($xlCellTypeLastCell).row
;MsgBox(0,"",$oRange)

Sleep(1000)

_Excel_RangeInsert($oWorkbook2.Activesheet, "A2:G2", $xlShiftDown , 1);Default)
_Excel_RangeWrite($oWorkbook2, Default,$SUserId,"A2")
_Excel_RangeWrite($oWorkbook2, Default,$Received_time,"B2")
_Excel_RangeWrite($oWorkbook2, Default, _NowTime(3), "C2")
_Excel_RangeWrite($oWorkbook2, Default, "Unable to Unlock ID", "D2")
_Excel_RangeWrite($oWorkbook2, Default, $FN_3, "E2")
_Excel_RangeWrite($oWorkbook2, Default, $EmailAddress_Sender, "F2") ;$EmailAddress_Sender ; $Email_3
$oWorkbook2.ActiveSheet.Columns("A:G").AutoFit
$oExcel3.ActiveSheet.Columns("A:G").HorizontalAlignment = $xlLeft ; Can be xlCenter, xlDistributed, xlJustify, xlLeft or xlRight of the XlHAlign enumeration.
$oExcel3.ActiveSheet.usedrange.Borders.LineStyle = 1
_Excel_BookClose($oWorkbook2, True)
_Excel_Close($oExcel3,false)

$oExcel3 = _Excel_Open()

If WinExists("Microsoft Excel","") = 1 Then
   ControlClick("Microsoft Excel","Close the program","Button2","left",1)
EndIf

$oWorkbook2 = _Excel_BookOpen($oExcel3, @ScriptDir & "\BP_Success.xlsx", Default, True)
$oWorkbook2.Sheets("Processed").Activate
;_Excel_RangeDelete ( $oWorksheet, $vRange [, $iShift = Default [, $iEntireRowCol = Default]] )
$oRange = $oWorkbook2.ActiveSheet.range("A2").SpecialCells($xlCellTypeLastCell).row
;MsgBox(0,"",$oRange)

Sleep(1000)

_Excel_RangeInsert($oWorkbook2.Activesheet, "A2:F2", $xlShiftDown , 1);Default)
_Excel_RangeWrite($oWorkbook2, Default,"NT LOGIN","A2")
_Excel_RangeWrite($oWorkbook2, Default,$SUserId,"B2")
_Excel_RangeWrite($oWorkbook2, Default, $fname, "C2")
_Excel_RangeWrite($oWorkbook2, Default, $sname, "D2")
_Excel_RangeWrite($oWorkbook2, Default, "N/A", "E2")
_Excel_RangeWrite($oWorkbook2, Default, "Unable to Unlock ID", "F2") ;$EmailAddress_Sender ; $Email_3
;_Excel_RangeWrite($oWorkbook2, Default, $EmailAddress_Sender, "G2") ;
$oWorkbook2.ActiveSheet.Columns("A:F").AutoFit
$oExcel3.ActiveSheet.Columns("A:F").HorizontalAlignment = $xlLeft ; Can be xlCenter, xlDistributed, xlJustify, xlLeft or xlRight of the XlHAlign enumeration.
$oExcel3.ActiveSheet.usedrange.Borders.LineStyle = 1
_Excel_BookClose($oWorkbook2, True)
_Excel_Close($oExcel3,false)

EndFunc

Func log_user_not_found() ;FOR user not found

    $oExcel3 = _Excel_Open()

If WinExists("Microsoft Excel","") = 1 Then
   ControlClick("Microsoft Excel","Close the program","Button2","left",1)
EndIf

$oWorkbook2 = _Excel_BookOpen($oExcel3, @ScriptDir & "\log_bp_pw.xlsx", Default, True)
$oWorkbook2.Sheets("Processed").Activate
;_Excel_RangeDelete ( $oWorksheet, $vRange [, $iShift = Default [, $iEntireRowCol = Default]] )
$oRange = $oWorkbook2.ActiveSheet.range("A2").SpecialCells($xlCellTypeLastCell).row
;MsgBox(0,"",$oRange)

Sleep(1000)

_Excel_RangeInsert($oWorkbook2.Activesheet, "A2:G2", $xlShiftDown , 1);Default)
_Excel_RangeWrite($oWorkbook2, Default,$SUserId,"A2")
_Excel_RangeWrite($oWorkbook2, Default,$Received_time,"B2")
_Excel_RangeWrite($oWorkbook2, Default, _NowTime(3), "C2")
_Excel_RangeWrite($oWorkbook2, Default, "User ID not found", "D2")
_Excel_RangeWrite($oWorkbook2, Default, $FN_3, "E2")
_Excel_RangeWrite($oWorkbook2, Default, $EmailAddress_Sender, "F2") ;$EmailAddress_Sender ; $Email_3
$oWorkbook2.ActiveSheet.Columns("A:G").AutoFit
$oExcel3.ActiveSheet.Columns("A:G").HorizontalAlignment = $xlLeft ; Can be xlCenter, xlDistributed, xlJustify, xlLeft or xlRight of the XlHAlign enumeration.
$oExcel3.ActiveSheet.usedrange.Borders.LineStyle = 1
_Excel_BookClose($oWorkbook2, True)
_Excel_Close($oExcel3,false)

$oExcel3 = _Excel_Open()

If WinExists("Microsoft Excel","") = 1 Then
   ControlClick("Microsoft Excel","Close the program","Button2","left",1)
EndIf

$oWorkbook2 = _Excel_BookOpen($oExcel3, @ScriptDir & "\BP_Success.xlsx", Default, True)
$oWorkbook2.Sheets("Processed").Activate
;_Excel_RangeDelete ( $oWorksheet, $vRange [, $iShift = Default [, $iEntireRowCol = Default]] )
$oRange = $oWorkbook2.ActiveSheet.range("A2").SpecialCells($xlCellTypeLastCell).row
;MsgBox(0,"",$oRange)

Sleep(1000)

_Excel_RangeInsert($oWorkbook2.Activesheet, "A2:F2", $xlShiftDown , 1);Default)
_Excel_RangeWrite($oWorkbook2, Default,"NT LOGIN","A2")
_Excel_RangeWrite($oWorkbook2, Default,$SUserId,"B2")
_Excel_RangeWrite($oWorkbook2, Default, $fname, "C2")
_Excel_RangeWrite($oWorkbook2, Default, $sname, "D2")
_Excel_RangeWrite($oWorkbook2, Default, "N/A", "E2")
_Excel_RangeWrite($oWorkbook2, Default, "User ID not Found", "F2") ;$EmailAddress_Sender ; $Email_3
;_Excel_RangeWrite($oWorkbook2, Default, $EmailAddress_Sender, "G2") ;
$oWorkbook2.ActiveSheet.Columns("A:F").AutoFit
$oExcel3.ActiveSheet.Columns("A:F").HorizontalAlignment = $xlLeft ; Can be xlCenter, xlDistributed, xlJustify, xlLeft or xlRight of the XlHAlign enumeration.
$oExcel3.ActiveSheet.usedrange.Borders.LineStyle = 1
_Excel_BookClose($oWorkbook2, True)
_Excel_Close($oExcel3,false)

EndFunc

Func log_unlocked_and_reset() ;FOR unlocked and reset

    $oExcel3 = _Excel_Open()

If WinExists("Microsoft Excel","") = 1 Then
   ControlClick("Microsoft Excel","Close the program","Button2","left",1)
EndIf

$oWorkbook2 = _Excel_BookOpen($oExcel3, @ScriptDir & "\log_bp_pw.xlsx", Default, True)
$oWorkbook2.Sheets("Processed").Activate
;_Excel_RangeDelete ( $oWorksheet, $vRange [, $iShift = Default [, $iEntireRowCol = Default]] )
$oRange = $oWorkbook2.ActiveSheet.range("A2").SpecialCells($xlCellTypeLastCell).row
;MsgBox(0,"",$oRange)

Sleep(1000)

_Excel_RangeInsert($oWorkbook2.Activesheet, "A2:G2", $xlShiftDown , 1);Default)
_Excel_RangeWrite($oWorkbook2, Default,$SUserId,"A2")
_Excel_RangeWrite($oWorkbook2, Default,$Received_time,"B2")
_Excel_RangeWrite($oWorkbook2, Default, _NowTime(3), "C2")
_Excel_RangeWrite($oWorkbook2, Default, "Unlock and reset Successful", "D2")
_Excel_RangeWrite($oWorkbook2, Default, $FN_3, "E2")
_Excel_RangeWrite($oWorkbook2, Default, $EmailAddress_Sender, "F2") ;$EmailAddress_Sender ; $Email_3
$oWorkbook2.ActiveSheet.Columns("A:G").AutoFit
$oExcel3.ActiveSheet.Columns("A:G").HorizontalAlignment = $xlLeft ; Can be xlCenter, xlDistributed, xlJustify, xlLeft or xlRight of the XlHAlign enumeration.
$oExcel3.ActiveSheet.usedrange.Borders.LineStyle = 1
_Excel_BookClose($oWorkbook2, True)
_Excel_Close($oExcel3,false)

$oExcel3 = _Excel_Open()

If WinExists("Microsoft Excel","") = 1 Then
   ControlClick("Microsoft Excel","Close the program","Button2","left",1)
EndIf

$oWorkbook2 = _Excel_BookOpen($oExcel3, @ScriptDir & "\BP_Success.xlsx", Default, True)
$oWorkbook2.Sheets("Processed").Activate
;_Excel_RangeDelete ( $oWorksheet, $vRange [, $iShift = Default [, $iEntireRowCol = Default]] )
$oRange = $oWorkbook2.ActiveSheet.range("A2").SpecialCells($xlCellTypeLastCell).row
;MsgBox(0,"",$oRange)

Sleep(1000)

_Excel_RangeInsert($oWorkbook2.Activesheet, "A2:F2", $xlShiftDown , 1);Default)
_Excel_RangeWrite($oWorkbook2, Default,"NT LOGIN","A2")
_Excel_RangeWrite($oWorkbook2, Default,$SUserId,"B2")
_Excel_RangeWrite($oWorkbook2, Default, $fname, "C2")
_Excel_RangeWrite($oWorkbook2, Default, $sname, "D2")
_Excel_RangeWrite($oWorkbook2, Default, $password, "E2")
_Excel_RangeWrite($oWorkbook2, Default, "Unlock and reset successful", "F2") ;$EmailAddress_Sender ; $Email_3
;_Excel_RangeWrite($oWorkbook2, Default, $EmailAddress_Sender, "G2") ;
$oWorkbook2.ActiveSheet.Columns("A:F").AutoFit
$oExcel3.ActiveSheet.Columns("A:F").HorizontalAlignment = $xlLeft ; Can be xlCenter, xlDistributed, xlJustify, xlLeft or xlRight of the XlHAlign enumeration.
$oExcel3.ActiveSheet.usedrange.Borders.LineStyle = 1
_Excel_BookClose($oWorkbook2, True)
_Excel_Close($oExcel3,false)

EndFunc

Func log_reset_only() ;FOR reset only
    $oExcel3 = _Excel_Open()

If WinExists("Microsoft Excel","") = 1 Then
   ControlClick("Microsoft Excel","Close the program","Button2","left",1)
EndIf

$oWorkbook2 = _Excel_BookOpen($oExcel3, @ScriptDir & "\log_bp_pw.xlsx", Default, True)
$oWorkbook2.Sheets("Processed").Activate
;_Excel_RangeDelete ( $oWorksheet, $vRange [, $iShift = Default [, $iEntireRowCol = Default]] )
$oRange = $oWorkbook2.ActiveSheet.range("A2").SpecialCells($xlCellTypeLastCell).row
;MsgBox(0,"",$oRange)

Sleep(1000)

_Excel_RangeInsert($oWorkbook2.Activesheet, "A2:G2", $xlShiftDown , 1);Default)
_Excel_RangeWrite($oWorkbook2, Default,$SUserId,"A2")
_Excel_RangeWrite($oWorkbook2, Default,$Received_time,"B2")
_Excel_RangeWrite($oWorkbook2, Default, _NowTime(3), "C2")
_Excel_RangeWrite($oWorkbook2, Default, "not locked - Reset only", "D2")
_Excel_RangeWrite($oWorkbook2, Default, $FN_3, "E2")
_Excel_RangeWrite($oWorkbook2, Default, $EmailAddress_Sender, "F2") ;$EmailAddress_Sender ; $Email_3
$oWorkbook2.ActiveSheet.Columns("A:G").AutoFit
$oExcel3.ActiveSheet.Columns("A:G").HorizontalAlignment = $xlLeft ; Can be xlCenter, xlDistributed, xlJustify, xlLeft or xlRight of the XlHAlign enumeration.
$oExcel3.ActiveSheet.usedrange.Borders.LineStyle = 1
_Excel_BookClose($oWorkbook2, True)
_Excel_Close($oExcel3,false)

$oExcel3 = _Excel_Open()

If WinExists("Microsoft Excel","") = 1 Then
   ControlClick("Microsoft Excel","Close the program","Button2","left",1)
EndIf

$oWorkbook2 = _Excel_BookOpen($oExcel3, @ScriptDir & "\BP_Success.xlsx", Default, True)
$oWorkbook2.Sheets("Processed").Activate
;_Excel_RangeDelete ( $oWorksheet, $vRange [, $iShift = Default [, $iEntireRowCol = Default]] )
$oRange = $oWorkbook2.ActiveSheet.range("A2").SpecialCells($xlCellTypeLastCell).row
;MsgBox(0,"",$oRange)

Sleep(1000)

_Excel_RangeInsert($oWorkbook2.Activesheet, "A2:F2", $xlShiftDown , 1);Default)
_Excel_RangeWrite($oWorkbook2, Default,"NT LOGIN","A2")
_Excel_RangeWrite($oWorkbook2, Default,$SUserId,"B2")
_Excel_RangeWrite($oWorkbook2, Default, $fname, "C2")
_Excel_RangeWrite($oWorkbook2, Default, $sname, "D2")
_Excel_RangeWrite($oWorkbook2, Default, $password, "E2")
_Excel_RangeWrite($oWorkbook2, Default, "Not locked - Reset Only", "F2") ;$EmailAddress_Sender ; $Email_3
;_Excel_RangeWrite($oWorkbook2, Default, $EmailAddress_Sender, "G2") ;
$oWorkbook2.ActiveSheet.Columns("A:F").AutoFit
$oExcel3.ActiveSheet.Columns("A:F").HorizontalAlignment = $xlLeft ; Can be xlCenter, xlDistributed, xlJustify, xlLeft or xlRight of the XlHAlign enumeration.
$oExcel3.ActiveSheet.usedrange.Borders.LineStyle = 1
_Excel_BookClose($oWorkbook2, True)
_Excel_Close($oExcel3,false)

EndFunc


Func _email_successful()

Local $oExcel = _Excel_Open()
Local $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\BP_Success.xlsx")
Local $oRange = $oWorkbook.ActiveSheet.Usedrange.Columns("A:F").select
    $oExcel.CopyObjectsWithCells = True
    $oExcel.Selection.Copy

Local $oOutlook = ObjCreate("Outlook.Application")
Local $oMail = $oOutlook.CreateItem(0)
    $oMail.Display
    $oMail.To = "xxx.yyy@domain.com" ; removed my email for confidentiality
    $oMail.Subject = "BP Successful Reset via Automation"
    ;$oMail.attachments.add(@ScriptDir & "\VM_Incorrect.xlsx")

Local $sBodyHeader = "Hi " & @CRLF & @CRLF & "You are receiving this email because you requested to unlocked/reset the password of the following, please see status below: " & @CRLF & @CRLF & @CRLF

Local $sBodyFooter = @CRLF & @CRLF & " " & @CRLF & @CRLF & @CRLF

Local $oWordEditor = $oOutlook.ActiveInspector.wordEditor
    $oWordEditor.Range(0, 0).Select
    $oWordEditor.Application.Selection.TypeText($sBodyHeader)
    $oWordEditor.Application.Selection.Paste
    $oWordEditor.Application.Selection.TypeText($sBodyFooter)

$oMail.Display
$oMail.Send

Sleep(3000)
_Excel_BookClose($oExcel,false)
_Excel_Close($oExcel)


EndFunc

;=========================================================================
;======================== Logs Functions fallouts ========================
;=========================================================================

Func log_invalid_NT_ID() ;FOR Incorrect NT ID

$oExcel2 = _Excel_Open()

If WinExists("Microsoft Excel","") = 1 Then
   ControlClick("Microsoft Excel","Close the program","Button2","left",1)
EndIf

$oWorkbook2 = _Excel_BookOpen($oExcel2, @ScriptDir & "\log_bp_pw.xlsx", Default, True)
$oWorkbook2.Sheets("Fall outs").Activate
;_Excel_RangeDelete ( $oWorksheet, $vRange [, $iShift = Default [, $iEntireRowCol = Default]] )
$oRange = $oWorkbook2.ActiveSheet.range("A2").SpecialCells($xlCellTypeLastCell).row
;MsgBox(0,"",$oRange)

Sleep(1000)

_Excel_RangeInsert($oWorkbook2.Activesheet, "A2:E2", $xlShiftDown , 1);Default)
_Excel_RangeWrite($oWorkbook2, Default, $Received_time, "A2")
_Excel_RangeWrite($oWorkbook2, Default, "Invalid NT ID", "B2")
_Excel_RangeWrite($oWorkbook2, Default, _NowTime(3), "C2")
_Excel_RangeWrite($oWorkbook2, Default, $FN_3, "D2")
_Excel_RangeWrite($oWorkbook2, Default, $EmailAddress_Sender, "E2") ;$EmailAddress_Sender ; $Email_3
$oWorkbook2.ActiveSheet.Columns("A:E").AutoFit
$oExcel2.ActiveSheet.Columns("A:E").HorizontalAlignment = $xlLeft ; Can be xlCenter, xlDistributed, xlJustify, xlLeft or xlRight of the XlHAlign enumeration.
$oExcel2.ActiveSheet.usedrange.Borders.LineStyle = 1
_Excel_BookClose($oWorkbook2, True)
_Excel_Close($oExcel2,false)


EndFunc

Func log_invalid_Fname() ;FOR Incorrect Full Name

   $oExcel2 = _Excel_Open()

If WinExists("Microsoft Excel","") = 1 Then
   ControlClick("Microsoft Excel","Close the program","Button2","left",1)
EndIf

$oWorkbook2 = _Excel_BookOpen($oExcel2, @ScriptDir & "\log_bp_pw.xlsx", Default, True)
$oWorkbook2.Sheets("Fall outs").Activate
;_Excel_RangeDelete ( $oWorksheet, $vRange [, $iShift = Default [, $iEntireRowCol = Default]] )
$oRange = $oWorkbook2.ActiveSheet.range("A2").SpecialCells($xlCellTypeLastCell).row
;MsgBox(0,"",$oRange)

Sleep(1000)

_Excel_RangeInsert($oWorkbook2.Activesheet, "A2:E2", $xlShiftDown , 1);Default)
_Excel_RangeWrite($oWorkbook2, Default, $Received_time, "A2")
_Excel_RangeWrite($oWorkbook2, Default, "Invalid Full Name", "B2")
_Excel_RangeWrite($oWorkbook2, Default, _NowTime(3), "C2")
_Excel_RangeWrite($oWorkbook2, Default, $FN_3, "D2")
_Excel_RangeWrite($oWorkbook2, Default, $EmailAddress_Sender, "E2") ;$EmailAddress_Sender ; $Email_3
$oWorkbook2.ActiveSheet.Columns("A:E").AutoFit
$oExcel2.ActiveSheet.Columns("A:E").HorizontalAlignment = $xlLeft ; Can be xlCenter, xlDistributed, xlJustify, xlLeft or xlRight of the XlHAlign enumeration.
$oExcel2.ActiveSheet.usedrange.Borders.LineStyle = 1
_Excel_BookClose($oWorkbook2, True)
_Excel_Close($oExcel2,false)


EndFunc

Func log_invalid_Email() ;FOR Incorrect Email

$oExcel2 = _Excel_Open()

If WinExists("Microsoft Excel","") = 1 Then
   ControlClick("Microsoft Excel","Close the program","Button2","left",1)
EndIf

$oWorkbook2 = _Excel_BookOpen($oExcel2, @ScriptDir & "\log_bp_pw.xlsx", Default, True)
$oWorkbook2.Sheets("Fall outs").Activate
;_Excel_RangeDelete ( $oWorksheet, $vRange [, $iShift = Default [, $iEntireRowCol = Default]] )
$oRange = $oWorkbook2.ActiveSheet.range("A2").SpecialCells($xlCellTypeLastCell).row
;MsgBox(0,"",$oRange)

Sleep(1000)

_Excel_RangeInsert($oWorkbook2.Activesheet, "A2:E2", $xlShiftDown , 1);Default)
_Excel_RangeWrite($oWorkbook2, Default, $Received_time, "A2")
_Excel_RangeWrite($oWorkbook2, Default, "Invalid Email Address", "B2")
_Excel_RangeWrite($oWorkbook2, Default, _NowTime(3), "C2")
_Excel_RangeWrite($oWorkbook2, Default, $FN_3, "D2")
_Excel_RangeWrite($oWorkbook2, Default, $EmailAddress_Sender, "E2") ;$EmailAddress_Sender ; $Email_3
$oWorkbook2.ActiveSheet.Columns("A:E").AutoFit
$oExcel2.ActiveSheet.Columns("A:E").HorizontalAlignment = $xlLeft ; Can be xlCenter, xlDistributed, xlJustify, xlLeft or xlRight of the XlHAlign enumeration.
$oExcel2.ActiveSheet.usedrange.Borders.LineStyle = 1
_Excel_BookClose($oWorkbook2, True)
_Excel_Close($oExcel2,false)


EndFunc

Func log_invalid_security_code() ;FOR Incorrect Security Code

   $oExcel2 = _Excel_Open()

If WinExists("Microsoft Excel","") = 1 Then
   ControlClick("Microsoft Excel","Close the program","Button2","left",1)
EndIf

$oWorkbook2 = _Excel_BookOpen($oExcel2, @ScriptDir & "\log_bp_pw.xlsx", Default, True)
$oWorkbook2.Sheets("Fall outs").Activate
;_Excel_RangeDelete ( $oWorksheet, $vRange [, $iShift = Default [, $iEntireRowCol = Default]] )
$oRange = $oWorkbook2.ActiveSheet.range("A2").SpecialCells($xlCellTypeLastCell).row
;MsgBox(0,"",$oRange)

Sleep(1000)

_Excel_RangeInsert($oWorkbook2.Activesheet, "A2:E2", $xlShiftDown , 1);Default)
_Excel_RangeWrite($oWorkbook2, Default, $Received_time, "A2")
_Excel_RangeWrite($oWorkbook2, Default, "Invalid Security Code", "B2")
_Excel_RangeWrite($oWorkbook2, Default, _NowTime(3), "C2")
_Excel_RangeWrite($oWorkbook2, Default, $FN_3, "D2")
_Excel_RangeWrite($oWorkbook2, Default, $EmailAddress_Sender, "E2") ;$EmailAddress_Sender ; $Email_3
$oWorkbook2.ActiveSheet.Columns("A:E").AutoFit
$oExcel2.ActiveSheet.Columns("A:E").HorizontalAlignment = $xlLeft ; Can be xlCenter, xlDistributed, xlJustify, xlLeft or xlRight of the XlHAlign enumeration.
$oExcel2.ActiveSheet.usedrange.Borders.LineStyle = 1
_Excel_BookClose($oWorkbook2, True)
_Excel_Close($oExcel2,false)


EndFunc

Func log_invalid_phone() ;FOR Incorrect phone number

   $oExcel2 = _Excel_Open()

If WinExists("Microsoft Excel","") = 1 Then
   ControlClick("Microsoft Excel","Close the program","Button2","left",1)
EndIf

$oWorkbook2 = _Excel_BookOpen($oExcel2, @ScriptDir & "\log_bp_pw.xlsx", Default, True)
$oWorkbook2.Sheets("Fall outs").Activate
;_Excel_RangeDelete ( $oWorksheet, $vRange [, $iShift = Default [, $iEntireRowCol = Default]] )
$oRange = $oWorkbook2.ActiveSheet.range("A2").SpecialCells($xlCellTypeLastCell).row
;MsgBox(0,"",$oRange)

Sleep(1000)

_Excel_RangeInsert($oWorkbook2.Activesheet, "A2:E2", $xlShiftDown , 1);Default)
_Excel_RangeWrite($oWorkbook2, Default, $Received_time, "A2")
_Excel_RangeWrite($oWorkbook2, Default, "Invalid Phone Number", "B2")
_Excel_RangeWrite($oWorkbook2, Default, _NowTime(3), "C2")
_Excel_RangeWrite($oWorkbook2, Default, $FN_3, "D2")
_Excel_RangeWrite($oWorkbook2, Default, $EmailAddress_Sender, "E2") ;$EmailAddress_Sender ; $Email_3
$oWorkbook2.ActiveSheet.Columns("A:E").AutoFit
$oExcel2.ActiveSheet.Columns("A:E").HorizontalAlignment = $xlLeft ; Can be xlCenter, xlDistributed, xlJustify, xlLeft or xlRight of the XlHAlign enumeration.
$oExcel2.ActiveSheet.usedrange.Borders.LineStyle = 1
_Excel_BookClose($oWorkbook2, True)
_Excel_Close($oExcel2,false)


EndFunc

Func log_invalid_vendor_name() ;FOR Incorrect Vendor Name

   $oExcel2 = _Excel_Open()

If WinExists("Microsoft Excel","") = 1 Then
   ControlClick("Microsoft Excel","Close the program","Button2","left",1)
EndIf

$oWorkbook2 = _Excel_BookOpen($oExcel2, @ScriptDir & "\log_bp_pw.xlsx", Default, True)
$oWorkbook2.Sheets("Fall outs").Activate
;_Excel_RangeDelete ( $oWorksheet, $vRange [, $iShift = Default [, $iEntireRowCol = Default]] )
$oRange = $oWorkbook2.ActiveSheet.range("A2").SpecialCells($xlCellTypeLastCell).row
;MsgBox(0,"",$oRange)

Sleep(1000)

_Excel_RangeInsert($oWorkbook2.Activesheet, "A2:E2", $xlShiftDown , 1);Default)
_Excel_RangeWrite($oWorkbook2, Default, $Received_time, "A2")
_Excel_RangeWrite($oWorkbook2, Default, "Invalid Vendor Name", "B2")
_Excel_RangeWrite($oWorkbook2, Default, _NowTime(3), "C2")
_Excel_RangeWrite($oWorkbook2, Default, $FN_3, "D2")
_Excel_RangeWrite($oWorkbook2, Default, $EmailAddress_Sender, "E2") ;$EmailAddress_Sender ; $Email_3
$oWorkbook2.ActiveSheet.Columns("A:E").AutoFit
$oExcel2.ActiveSheet.Columns("A:E").HorizontalAlignment = $xlLeft ; Can be xlCenter, xlDistributed, xlJustify, xlLeft or xlRight of the XlHAlign enumeration.
$oExcel2.ActiveSheet.usedrange.Borders.LineStyle = 1
_Excel_BookClose($oWorkbook2, True)
_Excel_Close($oExcel2,false)


EndFunc


;=====================================================;
;=============== For Ticketing System ==================;
;=====================================================;

;_login2()

Func _login2()
   $oIE2 = _IECreate("Website") ; removed the website for confidentiality
   _IELoadWait($oIE2)
   Sleep(1000)
   $uname = _IEGetObjByName($oIE2, "username")
   $pass = _IEGetObjByName($oIE2, "pwd")
   $submit = _IEGetObjByName($oIE2, "login")
   $title = _IEPropertyGet($oIE2, "title")
   Sleep(1000)
   Opt("WinTitleMatchMode", 2)

   WinActivate ("BMC Remedy Mid Tier 9.1 - Login")

   _IEFormElementSetValue($uname, "xxxxxxx")   ;I placed xxxxxx for confidentiality on this forum
   _IEFormElementSetValue($pass, "xxxxxx")    ;I placed xxxxxx for confidentiality on this forum

   Sleep(1000)
   _IEAction($pass, "click")

    Send("{ENTER}")
   _IELoadWait($oIE2)
   ;MsgBox(0,'', 'done loading')
   If WinExists("Home (Search) - Internet Explorer","") Then
      WinActivate("Home (Search) - Internet Explorer","")

   Local $sMyString = "customer"
   Local $oLinks = _IELinkGetCollection($oIE2)
   For $oLink In $oLinks
    Local $sLinkText = _IEPropertyGet($oLink, "innerText")
    If StringInStr($sLinkText, $sMyString) Then
        _IEAction($oLink, "click")
        ExitLoop
    EndIf
   Next
   _initiate()
   EndIf
EndFunc

Func _initiate()

   $request_id_final = $SUserId ;"bp-123456678";"bp-mdizon015"
   WinActivate ("Home (Search) - Internet Explorer")

   $idfield1 = _IEGetObjById($oIE2,"arid_WIN_0_682000107") ;"arid_WIN_0_682001112")

   _IEAction($idfield1, "focus")

   _IEFormElementSetValue($idfield1, $request_id_final)
   _IEAction($idfield1, "focus")

   Send("{space}")
   Sleep(500)
   Send("{backspace}")
   Sleep(500)
   Send("{enter}")
   Sleep(3000)


   _ID_not_found() ; if BP ID is not found


EndFunc

Func _createticket_amelia()

   WinActivate("Home (Search) - Internet Explorer","")

   Local $sMyString = "create a new service request"
   Local $oLinks = _IELinkGetCollection($oIE2)
   For $oLink In $oLinks
      Local $sLinkText = _IEPropertyGet($oLink, "innerText")
      If StringInStr($sLinkText, $sMyString) Then
           _IEAction($oLink, "click")
           ExitLoop
      EndIf
   Next
   Sleep(5000)


_click_cancel()

   Sleep(3000)

If WinExists("Create a New Service Request (Search) - Internet Explorer","") Then
   WinActivate("Create a New Service Request (Search) - Internet Explorer","")
   WinSetState("Create a New Service Request (Search) - Internet Explorer","",@SW_MAXIMIZE)
   _click_close()
   sleep(3000)

   If WinExists("Create a New Service Request (Search) - Internet Explorer","") Then
   WinActivate("Create a New Service Request (Search) - Internet Explorer","")
   WinSetState("Create a New Service Request (Search) - Internet Explorer","",@SW_MAXIMIZE)

  sleep(3000)

   _click_Enter_Manually()

   _click_dropdown()
      sleep(300)
      send("{left}")
      sleep(300)
      send("{P}")
      sleep(300)
      send("{right}")
      sleep(300)
      Send("{P " & 3 & "}")
      sleep(300)
      send("{right}")
      sleep(300)
      send("{2}")
      sleep(300)
      Send("{UP " & 4 & "}")
      sleep(300)
      send("{Enter}")
      sleep(300)
      _click_Name1()
      _click_Email1()
      _phone1()
      _click_login_id1()
      sleep(300)
      _click_keyword()
      ;sleep(300)
      _click_arrowdown()
      sleep(1000)
      _click_drop_email()
      sleep(300)
      send("{UP}")
      sleep(300)
      send("{E}")
      sleep(300)
      send("{Enter}")
      sleep(300)
      _click_write_email()
      sleep(300)
      send("Password Reset request for " & $SUserId) ;($body) ($user_ID)
      sleep(300)

      _click_Name2()

      _click_Email2()

      _phone2()

      _click_login_id2()

      _click_submit()
      sleep(3000)
      _Service_request()
      sleep(5000)
      ticket_capture()
      sleep(3000)
      _click_acknowledge()
      sleep(3000)
      _click_Completed()
      sleep(4000)
      _click_keyword_completed()
      sleep(2000)
      _click_resolution()
      sleep(2000)
      _click_save_completed()
      sleep(2000)
      WinClose ("ESM:SR2 (Search) - Internet Explorer" ,"")
      sleep(1000)
      WinClose ("Create a New Service Request (Search) - Internet Explorer" ,"")
      sleep(2000)
      _IEQuit($oIE2)
      sleep(1000)
      If WinExists("ESM:SR2 (Search) - Internet Explorer" ,"") then
      WinClose ("ESM:SR2 (Search) - Internet Explorer" ,"")
      EndIf
      sleep(1000)
      If WinExists("Create a New Service Request (Search) - Internet Explorer" ,"")then
      WinClose ("Create a New Service Request (Search) - Internet Explorer" ,"")
      EndIf
      sleep(5000)
      log_tickets()

      EndIf

EndIf

EndFunc

Func _createticket_normal()

   WinActivate("Home (Search) - Internet Explorer","")
   Local $sMyString = "create a new service request"
   Local $oLinks = _IELinkGetCollection($oIE2)
   For $oLink In $oLinks
      Local $sLinkText = _IEPropertyGet($oLink, "innerText")
      If StringInStr($sLinkText, $sMyString) Then
           _IEAction($oLink, "click")
           ExitLoop
      EndIf
   Next
   Sleep(5000)


   _click_cancel()


   Sleep(3000)

If WinExists("Create a New Service Request (Search) - Internet Explorer","") Then
   WinActivate("Create a New Service Request (Search) - Internet Explorer","")
   WinSetState("Create a New Service Request (Search) - Internet Explorer","",@SW_MAXIMIZE)
   _click_close()
   sleep(3000)

   If WinExists("Create a New Service Request (Search) - Internet Explorer","") Then
   WinActivate("Create a New Service Request (Search) - Internet Explorer","")
   WinSetState("Create a New Service Request (Search) - Internet Explorer","",@SW_MAXIMIZE)

  sleep(3000)

   _click_Enter_Manually()

   _click_dropdown()
      sleep(300)
      send("{left}")
      sleep(300)
      send("{P}")
      sleep(300)
      send("{right}")
      sleep(300)
      Send("{P " & 3 & "}")
      sleep(300)
      send("{right}")
      sleep(300)
      send("{2}")
      sleep(300)
      Send("{UP " & 4 & "}")
      sleep(300)
      send("{Enter}")
      sleep(300)
      _click_Name1()
   _click_Email1()
   _phone1_VM()
   _click_login_id1()
   sleep(300)
   _click_keyword()

   _click_arrowdown()
   sleep(1000)
   _click_drop_email()
   sleep(300)
   send("{UP}")
   sleep(300)
   send("{E}")
   sleep(300)
   send("{Enter}")
   sleep(300)
   _click_write_email()
   sleep(300)
   send("Password Reset request for " & $SUserId) ;($body) ($user_ID)
   sleep(300)

   _click_Name2()

   _click_Email2()

   _phone2_VM()

   _click_login_id2()

      _click_submit()
      sleep(3000)
      _Service_request()
      sleep(5000)
      ticket_capture()
      sleep(3000)
      _click_acknowledge()
      sleep(3000)
      _click_Completed()
      sleep(4000)
      _click_keyword_completed()
      sleep(2000)
      _click_resolution()
      sleep(2000)
      _click_save_completed()
      sleep(2000)
      WinClose ("ESM:SR2 (Search) - Internet Explorer" ,"")
      sleep(1000)
      WinClose ("Create a New Service Request (Search) - Internet Explorer" ,"")
      sleep(2000)
      _IEQuit($oIE2)
      sleep(1000)
      If WinExists("ESM:SR2 (Search) - Internet Explorer" ,"") then
      WinClose ("ESM:SR2 (Search) - Internet Explorer" ,"")
      EndIf
      sleep(1000)
      If WinExists("Create a New Service Request (Search) - Internet Explorer" ,"")then
      WinClose ("Create a New Service Request (Search) - Internet Explorer" ,"")
      EndIf
      sleep(5000)
      log_tickets()


   EndIf

EndIf


EndFunc

Func _click_dropdown()

$x1=0
$y1=0
;_ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance)
$result = _ImageSearch("dropdown.png",1,$x1,$y1,100)
if $result = 1 Then
    MouseMove($x1,$y1,3)
    ;sleep(1000)
    MouseClick("left",$x1-5,$y1-1,1)
Else
    MsgBox(0,"dropdown.png","not found")

EndIf


EndFunc

Func _click_close()
$x1=0
$y1=0
;_ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance)
$result = _ImageSearch("close.png",1,$x1,$y1,50)
if $result = 1 Then
    MouseMove($x1,$y1,3)
    MouseClick("left",$x1,$y1,2)
    ;MsgBox(0,"Found","Found a recycle bin with stuff here...")
 Else
    MsgBox(0,"close.png","not found")
    Exit
 EndIf

EndFunc

Func _click_close_final()
$x1=0
$y1=0
;_ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance)
$result = _ImageSearch("close_final.png",1,$x1,$y1,50)
if $result = 1 Then
    MouseMove($x1,$y1,3)
    MouseClick("left",$x1,$y1,2)
    ;MsgBox(0,"Found","Found a recycle bin with stuff here...")
 Else
    MsgBox(0,"close_final.png","not found")
    Exit
 EndIf

EndFunc

Func _click_cancel()

$x1=0
$y1=0
;_ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance)
$result = _ImageSearch("cancel.png",1,$x1,$y1,0)
   If $result=1 Then
    MouseMove($x1,$y1,3)
    MouseClick("left",$x1,$y1,2)
    ;MsgBox(0,"Found","Found a recycle bin with stuff here...")
 ;Else
    ;MsgBox(0,"cancel.png","not found")
    ;Exit
   EndIf
$result = _ImageSearchArea("cancel.png",1,0,0,200,200,$x1,$y1,0)
if $result=1 Then
    MouseMove($x1,$y1,3)
    ;MsgBox(0,"Found","Found a recycle bin with stuff in top left corner")
EndIf


EndFunc

Func _click_arrowdown()

$x1=0
$y1=0
;_ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance)
$result = _ImageSearch("arrowdown.png",1,$x1,$y1,0)
if $result = 1 Then
    MouseMove($x1,$y1,3)
    sleep(1000)
    MouseClick("left",$x1-4,$y1+3,1)
    ;MsgBox(0,"Found","Found a recycle bin with stuff here...")
 Else
    MsgBox(0,"arrowdown.png","not found")
    Exit
 EndIf

EndFunc

Func _click_write_email()

$x1=0
$y1=0
;_ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance)
$result = _ImageSearch("write_email.png",1,$x1,$y1,50)
if $result = 1 Then
    ;MouseMove($x1,$y1,3)
    sleep(500)
    MouseClick("left",$x1+20,$y1+10,1)
    ;MsgBox(0,"Found","Found a recycle bin with stuff here...")
Else
    MsgBox(0,"write_email","not found")
    Exit
 EndIf

EndFunc

Func _click_drop_email()

$x1=0
$y1=0
;_ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance)
$result = _ImageSearch("drop_email.png",1,$x1,$y1,100)
if $result = 1 Then
    MouseMove($x1,$y1,3)
    sleep(1000)
    MouseClick("left",$x1-16,$y1+3,1)
    ;MsgBox(0,"Found","Found a recycle bin with stuff here...")
 Else
    MsgBox(0,"Drop_email","not found")
    Exit
 EndIf

EndFunc

Func _click_keyword()

$x1=0
$y1=0
;_ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance)
$result = _ImageSearch("keyword.png",1,$x1,$y1,50)
if $result = 1 Then
    MouseMove($x1,$y1,3)
    sleep(2000)
    MouseClick("left",$x1+15,$y1-2,1)
      sleep(1000)
      send("87170")
      sleep(1000)
      send("{enter}")
      sleep(3000) ; 4000
         MouseMove($x1,$y1+40,3)
         sleep(1000)
         MouseClick("left",$x1,$y1+40,2)
         Else
    MsgBox(0,"keyword","not found")
    Exit
 EndIf

EndFunc

Func _click_local_admin()

$x1=0
$y1=0
;_ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance)
$result = _ImageSearch("local_admin.png",1,$x1,$y1,50)
if $result = 1 Then
    ;MouseMove($x1,$y1,3)
    sleep(1000)
    MouseClick("left",$x1,$y1,2)
    sleep(1000)
    MouseClick("left",$x1,$y1,2)
    sleep(1000)
    MouseClick("left",$x1,$y1+10,2)
    Else
    MsgBox(0,"local_admin","not found")
    Exit
 EndIf

EndFunc

Func _click_submit()

$x1=0
$y1=0
;_ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance)
$result = _ImageSearch("submit.png",1,$x1,$y1,50)
if $result = 1 Then
    MouseMove($x1,$y1,3)
    sleep(1000)
    MouseClick("left",$x1+1,$y1,1)
 Else
    MsgBox(0,"Submit","not found")
    Exit
 EndIf

EndFunc

Func _Service_request()

If WinExists("Create a New Service Request (Search) - Internet Explorer","") Then
   WinActivate("Create a New Service Request (Search) - Internet Explorer","")
   sleep(2000)
$x1=0
$y1=0
;_ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance)
$result = _ImageSearch("Service_request.png",1,$x1,$y1,0)
if $result = 1 Then
    MouseMove($x1,$y1,3)
    sleep(2000)
    ;MouseMove($x1+100,$y1,3)
    MouseClick("left",$x1+100,$y1,2)
    ;Send("N/A")
    ;MsgBox(0,"Found","Found a recycle bin with stuff here...")
 Else
    MsgBox(0,"Service_request.png","not found",3)

 $result = _ImageSearchArea("Service_request.png",1,0,0,200,200,$x1,$y1,0)
if $result=1 Then
    MouseMove($x1,$y1,3)
    sleep(2000)
    ;MouseMove($x1+100,$y1,3)
    MouseClick("left",$x1+100,$y1,2)
    ;MsgBox(0,"Found","Found a recycle bin with stuff in top left corner")
 EndIf
 EndIf
EndIf
EndFunc

Func _ID_not_found()
$x1=0
$y1=0
;_ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance)
$result = _ImageSearch("ID_not_found.png",1,$x1,$y1,0)
if $result = 1 Then
    MouseMove($x1-25,$y1+30,3)
    sleep(1000)
    MouseClick("left",$x1-25,$y1+30,3)
    sleep(3000)
    $request_id_final = "ainfos799";"bp-mdizon015"
    WinActivate ("Home (Search) - Internet Explorer")

   $idfield1 = _IEGetObjById($oIE2,"arid_WIN_0_682000107") ;"arid_WIN_0_682001112")
   _IEAction($idfield1, "focus")
   _IEFormElementSetValue($idfield1, $request_id_final) ;"bp-mdizon015") ;johoney_bernardino@cable.comcast.com
   _IEAction($idfield1, "focus")

   Send("{space}")
   Sleep(500)
   Send("{backspace}")
   Sleep(500)
   Send("{enter}")
   Sleep(500)
   _createticket_amelia()
    ;MsgBox(0,"Found","Found a recycle bin with stuff here...")
 Else
    ;MsgBox(0,"","not found")
    _createticket_normal()
 EndIf

EndFunc

Func ticket_capture()
    Local $hGUI

      If WinExists("ESM:SR2 (Search) - Internet Explorer","") Then
         WinActivate("ESM:SR2 (Search) - Internet Explorer","")
         WinSetState("ESM:SR2 (Search) - Internet Explorer","",@SW_MAXIMIZE)

                local $title = "ESM:SR2 (Search) - Internet Explorer"

               $hGUI = WinGetHandle("ESM:SR2 (Search) - Internet Explorer","");Untitled - Notepad
               ;
               sleep(3000)
                ; Capture window
                _ScreenCapture_CaptureWnd(@ScriptDir & "\ticket.jpg", $hGUI,227,22,374,52)
                ;MsgBox(0,"","Done")

               run('"\\Path\Capture2Text_v4.6.0_32bit\Capture2Text\Capture2Text_CLI.exe" -i ticket.jpg -o ticket.txt',"",@SW_HIDE) ; ; removed network Path due to confidentiality
                ;ShellExecute(@ScriptDir & "\testing.jpg")
                sleep(3000)
                local $file_1 = FileOpen(@scriptdir & "\ticket.txt",0)
                local $file_read = FileRead($file_1)
                $ticket_number = $file_read
                ;MsgBox(0,"",$ticket_number)

      EndIf
 EndFunc   ;==>Example

Func _click_acknowledge()

If WinExists("ESM:SR2 (Search) - Internet Explorer","") Then
   WinActivate("ESM:SR2 (Search) - Internet Explorer","")
   WinSetState("ESM:SR2 (Search) - Internet Explorer","",@SW_MAXIMIZE)

$x1=0
$y1=0
;_ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance)

   $result = _ImageSearch("acknowledge.png",1,$x1,$y1,0)
   If $result = 1 Then
       MouseMove($x1,$y1,3)
       sleep(2000)
       MouseClick("left",$x1,$y1,1)
    Else
      MsgBox(0,"acknowledge.png","not found")
      Exit
   EndIf
EndIf

EndFunc

Func _click_Completed()

$x1=0
$y1=0
;_ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance)
$result = _ImageSearch("completed.png",1,$x1,$y1,0)
if $result = 1 Then
    MouseMove($x1,$y1,3)
    sleep(2000)
    MouseClick("left",$x1,$y1,1)
Else
    MsgBox(0,"completed.png","not found")
    Exit
EndIf

EndFunc

Func _click_keyword_completed()

$x1=0
$y1=0
;_ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance)
$result = _ImageSearch("keyword_complete.png",1,$x1,$y1,100)
if $result = 1 Then
    MouseMove($x1,$y1,3)
    sleep(2000)
    MouseClick("left",$x1+15,$y1-2,1)
      sleep(1000)
      send("201")
      sleep(1000)
      send("{enter}")
      ;sleep(3000) ; 4000
   Else
      MsgBox(0,"keyword_complete - 1", "not found",2)
   ;Exit

   $result = _ImageSearchArea("keyword_complete.png",1,0,0,200,200,$x1,$y1,0)
if $result=1 Then
    MouseMove($x1,$y1,3)
    ;MsgBox(0,"Found","Found a recycle bin with stuff in top left corner")
EndIf
EndIf

EndFunc

Func _click_resolution()

$x1=0
$y1=0
;_ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance)
$result = _ImageSearch("resolution.png",1,$x1,$y1,0)
if $result = 1 Then
    MouseMove($x1,$y1,3)
    sleep(2000)
    MouseClick("left",$x1+15,$y1-2,1)
      sleep(1000)
      send("Request Completed")
      sleep(1000)
Else
    MsgBox(0,"resolution.png","not found")
    Exit
EndIf

EndFunc

Func _click_save_completed()

$x1=0
$y1=0
;_ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance)
$result = _ImageSearch("saved.png",1,$x1,$y1,100)
if $result = 1 Then
    MouseMove($x1,$y1,3)
    sleep(2000)
    MouseClick("left",$x1,$y1,1)
Else
    MsgBox(0,"saved.png","not found")
    Exit
EndIf

EndFunc

Func log_tickets() ;For Ticketing

 $oExcel3 = _Excel_Open()

If WinExists("Microsoft Excel","") = 1 Then
   ControlClick("Microsoft Excel","Close the program","Button2","left",1)
EndIf

$oWorkbook2 = _Excel_BookOpen($oExcel3, @ScriptDir & "\log_bp_pw.xlsx", Default, True)
$oWorkbook2.Sheets("Processed").Activate
;_Excel_RangeDelete ( $oWorksheet, $vRange [, $iShift = Default [, $iEntireRowCol = Default]] )
$oRange = $oWorkbook2.ActiveSheet.range("A2").SpecialCells($xlCellTypeLastCell).row
;MsgBox(0,"",$oRange)

Sleep(1000)

local $file_1 = FileOpen(@scriptdir & "\ticket.txt",0)
    local $file_read = FileRead($file_1)
    $ticket_number = $file_read
    ;MsgBox(0,"",$ticket_number)

   local $letter = "G"
   local $number = "1"
   local $cell = $letter & $number

   $value = _Excel_RangeRead($oWorkbook2,$oWorkbook2.activesheet,$letter & $number, Default)

   While $value <>"" or $value <> null or $value <> " "
      $number = $number + 1
      $value1 = _Excel_RangeRead($oWorkbook2,$oWorkbook2.activesheet,$letter & $number, Default)

      If $value1 = "" or $value1 = " " or $value1 = null Then
         _Excel_RangeWrite($oWorkbook2, $oWorkbook2.activesheet, $ticket_number, "G" & $number,false,false)
         $oWorkbook2.ActiveSheet.Columns("G").AutoFit
         ;$oExcel3.ActiveSheet.Columns("G").HorizontalAlignment = $xlLeft ; Can be xlCenter, xlDistributed, xlJustify, xlLeft or xlRight of the XlHAlign enumeration.
         _Excel_BookClose($oWorkbook2, True)
         _Excel_Close($oExcel3,false)
         ExitLoop
      EndIf
   WEnd

EndFunc

Func log_tickets_summary() ;For Ticketing summary

 $oExcel3 = _Excel_Open()

If WinExists("Microsoft Excel","") = 1 Then
   ControlClick("Microsoft Excel","Close the program","Button2","left",1)
EndIf

$oWorkbook2 = _Excel_BookOpen($oExcel3, @ScriptDir & "\log_bp_pw.xlsx", Default, True)
$oWorkbook2.Sheets("Processed").Activate
;_Excel_RangeDelete ( $oWorksheet, $vRange [, $iShift = Default [, $iEntireRowCol = Default]] )
$oRange = $oWorkbook2.ActiveSheet.range("A2").SpecialCells($xlCellTypeLastCell).row
;MsgBox(0,"",$oRange)

Sleep(1000)

_Excel_RangeInsert($oWorkbook2.Activesheet, "G2", $xlShiftDown , 1);Default)
_Excel_RangeWrite($oWorkbook2, Default,$SUserId,"A2")
_Excel_RangeWrite($oWorkbook2, Default,$Received_time,"B2")
_Excel_RangeWrite($oWorkbook2, Default, _NowTime(3), "C2")
_Excel_RangeWrite($oWorkbook2, Default, "Expired ID", "D2")
_Excel_RangeWrite($oWorkbook2, Default, $FN_3, "E2")
_Excel_RangeWrite($oWorkbook2, Default, $EmailAddress_Sender, "F2") ;$EmailAddress_Sender ; $Email_3
;_Excel_RangeWrite($oWorkbook2, Default, $EmailAddress_Sender, "G2") ;
$oWorkbook2.ActiveSheet.Columns("A:G").AutoFit
$oExcel3.ActiveSheet.Columns("A:G").HorizontalAlignment = $xlLeft ; Can be xlCenter, xlDistributed, xlJustify, xlLeft or xlRight of the XlHAlign enumeration.
_Excel_BookClose($oWorkbook2, True)
_Excel_Close($oExcel3,false)

EndFunc

;added functions

Func _click_login_id1()

$x1=0
$y1=0
;_ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance)
$result = _ImageSearch("login_id.png",1,$x1,$y1,100)
if $result = 1 Then
    MouseMove($x1,$y1,3)
    sleep(500)
    MouseClick("left",$x1+15,$y1-2,1)
      sleep(500)
      send($NT_3)
      sleep(500)
   Else
      MsgBox(0,"login_id.png", "not found")
      Exit
EndIf

EndFunc

Func _click_login_id2()

$x1=0
$y1=0
;_ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance)
$result = _ImageSearch("login_id2.png",1,$x1,$y1,100)
if $result = 1 Then
    MouseMove($x1,$y1,3)
    sleep(500)
    MouseClick("left",$x1+15,$y1-2,1)
      sleep(500)
      send($NT_3)
      sleep(500)
   Else
      MsgBox(0,"login_id2.png", "not found")
      Exit
EndIf

EndFunc

Func _click_Email1()

$x1=0
$y1=0
;_ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance)
$result = _ImageSearch("email1.png",1,$x1,$y1,100)
if $result = 1 Then
    MouseMove($x1,$y1,3)
    sleep(500)
    MouseClick("left",$x1+15,$y1-2,1)
      sleep(500)
      send($Email_3)
      sleep(500)
   Else
      MsgBox(0,"email1.png", "not found")
      Exit
EndIf

EndFunc

Func _click_Email2()

$x1=0
$y1=0
;_ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance)
$result = _ImageSearch("email2.png",1,$x1,$y1,100)
if $result = 1 Then
    MouseMove($x1,$y1,3)
    sleep(500)
    MouseClick("left",$x1+15,$y1-2,1)
      sleep(500)
      send($Email_3)
      sleep(500)
   Else
      MsgBox(0,"email2.png", "not found")
      Exit
EndIf

EndFunc

Func _click_Name1()

$x1=0
$y1=0
;_ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance)
$result = _ImageSearch("name1.png",1,$x1,$y1,100)
if $result = 1 Then
    MouseMove($x1,$y1,3)
    sleep(500)
    MouseClick("left",$x1+15,$y1-2,1)
      sleep(500)
      send($FN_3)
      sleep(500)
   Else
      MsgBox(0,"name1.png", "not found")
      Exit
EndIf

EndFunc

Func _click_Name2()

$x1=0
$y1=0
;_ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance)
$result = _ImageSearch("name2.png",1,$x1,$y1,100)
if $result = 1 Then
    MouseMove($x1,$y1,3)
    sleep(500)
    MouseClick("left",$x1+15,$y1-2,1)
      sleep(500)
      send($FN_3)
      sleep(500)
   Else
      MsgBox(0,"name2.png", "not found")
      Exit
EndIf

EndFunc

Func _click_Enter_Manually()

$x1=0
$y1=0
;_ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance)
$result = _ImageSearch("Enter_manually.png",1,$x1,$y1,100)
if $result = 1 Then
    MouseMove($x1,$y1,3)
    sleep(500)
    MouseClick("left",$x1+15,$y1-2,1)
   Else
      MsgBox(0,"Enter_manually.png", "not found")
      Exit
EndIf

EndFunc

Func _phone1()
$x1=0
$y1=0
;_ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance)
$result = _ImageSearch("phone1.png",1,$x1,$y1,100)
if $result = 1 Then
    MouseMove($x1,$y1,3)
    sleep(500)
    MouseClick("left",$x1+15,$y1,2)
    sleep(500)
    Send("N/A")
    ;MsgBox(0,"Found","Found a recycle bin with stuff here...")
 Else
    MsgBox(0,"phone1.png","not found")
    Exit
 EndIf

EndFunc

Func _phone2()
 $x1=0
 $y1=0
;_ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance)
$result = _ImageSearch("phone2.png",1,$x1,$y1,100)
if $result = 1 Then
    MouseMove($x1,$y1,3)
    sleep(500)
    MouseClick("left",$x1+15,$y1,2)
    sleep(500)
    Send("N/A")
    ;MsgBox(0,"Found","Found a recycle bin with stuff here...")
 Else
    MsgBox(0,"phone2.png","not found")
    Exit
 EndIf

EndFunc

Func _phone1_VM()
$x1=0
$y1=0
;_ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance)
$result = _ImageSearch("phone1.png",1,$x1,$y1,100)
if $result = 1 Then
    MouseMove($x1,$y1,3)
    sleep(500)
    MouseClick("left",$x1+15,$y1,2)
    sleep(500)
    Send($VSC_3)
    ;MsgBox(0,"Found","Found a recycle bin with stuff here...")
 Else
    MsgBox(0,"phone1.png","not found")
    Exit
 EndIf

EndFunc

Func _phone2_VM()
 $x1=0
 $y1=0
;_ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance)
$result = _ImageSearch("phone2.png",1,$x1,$y1,100)
if $result = 1 Then
    MouseMove($x1,$y1,3)
    sleep(500)
    MouseClick("left",$x1+15,$y1,2)
    sleep(500)
    Send($VSC_3)
    ;MsgBox(0,"Found","Found a recycle bin with stuff here...")
 Else
    MsgBox(0,"phone2.png","not found")
    Exit
 EndIf

EndFunc

 

AutoIT Error1.PNG

AutoIT Error2.PNG

  • 2 months later...
Posted

Hi Juvigy,

 

Sorry for the late response. When I manually run Vendor5 via Scite, it won't get the Appcrash. I haven't tried to compile it to 64 bit. Script was compiled in 32 bit.

I will try today and let you know. The Appcrash by the way randomly shows up while running the script then exits my script.

  • 5 months later...
Posted

Hi Guys,

 

Any updates on this thread?

I am still having errors with this Appcrash with autoit.

any help will be greatly appreciated.

Posted (edited)

at 2209 lines long, that is a monster. plus, no way to test, not that I would

you need to add logging and debug statements. I recommend using log4a.au3 for logging, don't msgbox only, log it so you can trace what is going on and do your own debugging, you wrote it after all.

And what's with all the ImageSearching?

the error is telling you something is going wrong with whatever uses OLEAUT32.DLL which is probably related to your excel stuff. 

also, have you never run Tidy on your code from the tools menu of the Scite editor? it makes it a much nicer pig to deal with.

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Posted

@TheOne23 I would highly recommend that you create a log file and log all the steps to identify the exact location in the script where it crashes.  When you have that location, you should make a runable snippet that replicates the problem.  Then we will be able to assist you. 

Posted

Hi EarthShine and Nine,

 

Thank you for your feeedbacks and inputs. I will definitely do that.

Can I have a copy of your log4a.au3 @Earthshine?

 

Thank you.

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...