#include #include #include #include #include #include #include #include #include #include #include #include #include #Include ; variables Local $sText Local $databaseNameParameter = "DevV692000_Comp8th_Martin"; This is a database name and it will come as parameter. Local $newUserIdParameter = "009" Local $LoggedInUserId = "002" Local $AccessLevelUserId = "002" Local $LoggedInUserPassword = "123456" Local $UserNameDescription = "Test User" Local $PasswordParameter = "123456" Local $FileName = "C:\DevV692000_Comp8th\PSLGLBL\Input_Files\format.xlsx" Local $CellRange = "A1:H1000" Local $Logfile = "C:\DevV692000_Comp8th\PSLGLBL\Logs\Execution-" & @MDAY & "-" & @MON & "-" & @YEAR & ".log" Global $hCtrl = 0 ;AutoItSetOption ( "option" [, param] ) Opt("TrayAutoPause", 0) ; Opt("TrayIconHide", 1) ; MouseMove(@DesktopWidth/2, @DesktopHeight/2) MouseClick($MOUSE_CLICK_LEFT,@DesktopWidth/2, @DesktopHeight/2) If FileExists($Logfile) = 0 Then _FileCreate($Logfile) EndIf ;Read the excel in one shot... Global $oExcel = _Excel_Open(False) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Global $oWorkbook = _Excel_BookOpen($oExcel, $FileName) If @error Then _WriteErrorLog("Error opening workbook " & $FileName & " " & "@error = " & @error & ", @extended = " & @extended) _Excel_Close($oExcel) Exit EndIf Local $aArray = _Excel_RangeRead($oWorkbook, Default, Default, 1) If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example 3", "Error reading from workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) ;_ArrayDisplay($aArray, "Excel UDF: _Excel_RangeRead Example 3 - Formulas in column A") _RefreshSystemTray(1000); Refresh system tray ;Lanuch the application Run("C:\DevV692000_Comp8th\PSLGLBL\Proclient.exe") ;Run("\\UK-LON-PROsup1\Profund64\Icons\profund_test.bat"); Path for Test ;RunWait("C:\DevV692000_Comp8th\PSLGLBL\Setup.bat") _WriteErrorLog("Launching application started..") ConsoleWrite("Launching application started..") ; Wait for window to become active WinWaitActive("[CLASS:ConsoleWindowClass]") WinWaitActive("[TITLE:Profund Initialisation... please wait; CLASS:ConsoleWindowClass;]", "") If(WinExists("Profund Initialisation... please wait","")) Then Send("Y{ENTER}") _WriteErrorLog("Hitting Y and Enter to Launch Profund Launcher ") ConsoleWrite("Hitting Y and Enter to Launch Profund Launcher" & @CRLF) Else _WriteErrorLog("Profund Not found.. ") ConsoleWrite("Not found.." & @CRLF) Exit EndIf Sleep(500) WinWaitActive("[CLASS:#32770]") If(WinExists("Profund Launcher","")) Then If Not FileExists($FileName) Then _WriteErrorLog("Excel File check", "Error: Can not locate file .. ") MsgBox($MB_SYSTEMMODAL, "Excel File check", "Error: Can not locate file " & $FileName) Exit EndIf For $x = 1 To UBound($aArray, 1) - 1 $newUserIdParameter = $aArray[$x][0] $UserNameDescription = $aArray[$x][1] $AccessLevelUserId = $aArray[$x][2] $databaseNameParameter = $aArray[$x][3] $PasswordParameter = $aArray[$x][4] $LoggedInUserId = $aArray[$x][5] $LoggedInUserPassword = $aArray[$x][6] ConsoleWrite("UserId => " & $newUserIdParameter & ", Name " & $UserNameDescription & ", AccessLevel " & $AccessLevelUserId & ", Database " & $databaseNameParameter & ", Passcode " & $PasswordParameter & ", UserName " & $LoggedInUserId & ", Password " & $LoggedInUserPassword & @CRLF) If StringLen($aArray[$x][0]) = 0 Then If ProcessExists("Master.exe") Then local $ProcessId = ProcessExists("Master.exe") ProcessClose($ProcessId) _WriteErrorLog("Master Process Terminated because all cases are completed") sleep (500) Exit EndIf EndIf IF $aArray[$x][7] = "Passed" Or $aArray[$x][7] = "Failed" Then ContinueLoop; Searching for cases which are not processed yet Else ; Launching the database window. Local $flagLaunchDatabase = LaunchDatabaseWindow($databaseNameParameter) if $flagLaunchDatabase <> True Then Sleep(500) ConsoleWrite("Failed while launching database window.." & @CRLF) _Excel_RangeWrite($oWorkbook,$oWorkbook.Activesheet,"Failed","H"&$x+1) Sleep(1000) _Excel_BookSave($oWorkbook) Sleep(1000) _Excel_Close($oExcel) Sleep(1000) TerminateProcess() EndIf Sleep(500) ; Launching Login Box. Local $flagLogin = Login($LoggedInUserId,$LoggedInUserPassword) If $flagLogin <> True Then Sleep(500) ConsoleWrite("Failed in Login Operation.." & @CRLF) _Excel_RangeWrite($oWorkbook,$oWorkbook.Activesheet,"Failed","H"&$x+1) Sleep(1000) _Excel_BookSave($oWorkbook) Sleep(1000) _Excel_Close($oExcel) Sleep(1000) TerminateProcess() EndIf Sleep(500) ; Perform User Deletion & Creation. Local $flagPerformOperation = PerformOperation($newUserIdParameter,$LoggedInUserId,$UserNameDescription,$PasswordParameter,$databaseNameParameter) If $flagPerformOperation <> True Then Sleep(500) ConsoleWrite("Failed in Perform Operation Method for user : " & $UserNameDescription & @CRLF) _WriteErrorLog("Failed in Perform Operation Method for user : " & $UserNameDescription & @CRLF) _Excel_RangeWrite($oWorkbook,$oWorkbook.Activesheet,"Failed","H"&$x+1) Sleep(1000) _Excel_BookSave($oWorkbook) Sleep(1000) _Excel_Close($oExcel) Sleep(1000) TerminateProcess() EndIf _WriteErrorLog("Record Number : " & $x & " Stopped Processing at ." & @HOUR & ":" & @MIN & ":" & @SEC ) ConsoleWrite("Record Number : " & $x & " Stopped Processing." & @HOUR & ":" & @MIN & ":" & @SEC &@CRLF ) _Excel_RangeWrite($oWorkbook,$oWorkbook.Activesheet,"Passed","H"&$x+1) Sleep(1000) _Excel_BookSave($oWorkbook) Sleep(1000) _Excel_Close($oExcel) Sleep(1000) TerminateProcess() EndIf Next Sleep(500) ConsoleWrite("All tasks completed. Shutting down all the proceesses" & @CRLF) TerminateProcess() _RefreshSystemTray(1000); Refresh system tray Exit EndIf Func _WriteErrorLog($strMessage) Local $LogTime = @HOUR & ":" & @MIN & ":" & @SEC Local $hFileOpen = FileOpen($Logfile, 9) FileWriteLine($hFileOpen, $LogTime & " " & $strMessage & @CRLF) FileClose($hFileOpen) EndFunc Func IfElementFound($handle) local $Waiting = True local $i = 0 While (1) ;Sleep(500) If $Waiting Then ;$handle = ControlGetHandle($strHandle) If $handle Then _WriteErrorLog( " Value of Handle : " & $handle) ConsoleWrite( " Value of Handle : " & $handle & @CRLF) $Waiting = False ExitLoop Else $i = $i + 1 If $i=500 Then _WriteErrorLog($handle & " not found due to timeout.") ConsoleWrite($handle & " not found due to timeout." & @CRLF) $Waiting = False ExitLoop EndIf EndIf EndIf WEnd If $i >= 500 Then Return False Else Return True EndIf EndFunc Func Kill() If ProcessExists("Pme32.exe") Then local $ProcessId = ProcessExists("Pme32.exe") ProcessClose($ProcessId) sleep (2000) EndIf If ProcessExists("Pmedde32.exe") Then local $ProcessId = ProcessExists("Pmedde32.exe") ProcessClose($ProcessId) sleep (2000) EndIf If ProcessExists("Pmespl32.exe") Then local $ProcessId = ProcessExists("Pmespl32.exe") ProcessClose($ProcessId) sleep (2000) EndIf If ProcessExists("Pmelkp32.exe") Then local $ProcessId = ProcessExists("Pmelkp32.exe") ProcessClose($ProcessId) sleep (2000) EndIf If ProcessExists("Profund.exe") Then local $ProcessId = ProcessExists("Profund.exe") ProcessClose($ProcessId) sleep (2000) EndIf If ProcessExists("Proclient.exe") Then local $ProcessId = ProcessExists("Proclient.exe") ProcessClose($ProcessId) sleep (2000) EndIf If ProcessExists("PmeLogin.exe") Then sleep (2000) local $ProcessId = ProcessExists("PmeLogin.exe") ConsoleWrite("Process Id for PmeLogin.exe => " & $ProcessId) ProcessClose($ProcessId) EndIf If ProcessExists("Excel.exe") Then sleep (2000) local $ProcessId = ProcessExists("Excel.exe") ConsoleWrite("Process Id for Excel.exe => " & $ProcessId) ProcessClose($ProcessId) EndIf _RefreshSystemTray(1000); Refresh system tray EndFunc Func TerminateProcess() Kill() Sleep(2000) Exit EndFunc Func _RefreshSystemTray($nDelay = 1000) ; Save Opt settings Local $oldMatchMode = Opt("WinTitleMatchMode", 4) Local $oldChildMode = Opt("WinSearchChildren", 1) Local $error = 0 Do; Pseudo loop Local $hWnd = WinGetHandle("classname=TrayNotifyWnd") If @error Then $error = 1 ExitLoop EndIf Local $hControl = ControlGetHandle($hWnd, "", "Button1") ; We're on XP and the Hide Inactive Icons button is there, so expand it If $hControl <> "" And ControlCommand($hWnd, "", $hControl, "IsVisible") Then ControlClick($hWnd, "", $hControl) Sleep($nDelay) EndIf Local $posStart = MouseGetPos() Local $posWin = WinGetPos($hWnd) Local $y = $posWin[1] While $y < $posWin[3] + $posWin[1] Local $x = $posWin[0] While $x < $posWin[2] + $posWin[0] DllCall("user32.dll", "int", "SetCursorPos", "int", $x, "int", $y) If @error Then $error = 2 ExitLoop 3; Jump out of While/While/Do EndIf $x = $x + 8 WEnd $y = $y + 8 WEnd DllCall("user32.dll", "int", "SetCursorPos", "int", $posStart[0], "int", $posStart[1]) ; We're on XP so we need to hide the inactive icons again. If $hControl <> "" And ControlCommand($hWnd, "", $hControl, "IsVisible") Then ControlClick($hWnd, "", $hControl) EndIf Until 1 ; Restore Opt settings Opt("WinTitleMatchMode", $oldMatchMode) Opt("WinSearchChildren", $oldChildMode) SetError($error) EndFunc; _RefreshSystemTray()