RogFleming Posted July 24, 2009 Posted July 24, 2009 I tried to create an execuable to show the user the process of logging to an application, I want the script which is actually logging the user in to update the progress bar as events happen. I tried stdin/stdout and consolein/out, but could never get them to work correctly. I got an idea the maybe using TCP connections would allow a seperate process to send data to the progressbar. As you can see I borrowed from previous posts and it does work correctly. If you see what I trying to do does anyone know how to do this with stdin/stdout or console/in/out. ProgressBar update listener expandcollapse popupGlobal $l_IP = @IPAddress1 ; Set the listening IP Global $conned = False ; Set the conned var to false (really no use for this... Used it in an older version. will be removed soon.) Global $ConnectedSocket = "" TCPStartUp() ; Starts TCP services $MainSocket = TCPListen ($l_IP, 65432, 1000 ) ; Start a listening socket If $MainSocket = -1 Then Exit ; If a socket can't be created, exit the server EndIf _waitForConn() ; Start the loop that makes the program look for clients. Func _waitForConn() While $conned = False ; Look for client connection loop $ConnectedSocket = TCPAccept ($MainSocket) ;MsgBox(0,"Received Data1",$ConnectedSocket,5) ; Check if somebody wants to connect If $ConnectedSocket >= 0 Then ; If a client tries to connect, let him do so. ;Beep(500,120) ; Make a beep (for debugging purposes) $conned = True ; Set the conned var to true (really no use for this... Used it in an older version. will be removed soon.) _iAmConned() ; Start the connected loop. EndIf WEnd MsgBox(0,"Received Date",$ConnectedSocket,5) EndFunc Func _iAmConned() While $conned = True ; If connected, then... $pack = TCPRecv ($ConnectedSocket, 2048) ; Recive packages... If $pack <> "" Then ;ToolTip("SERVER: New client connected."&@CRLF&"Receiving Data: " & " " & $pack,10,50) _ProgressBar($pack) ; Open them and check if they are empty. If they are NOT empty, run the payload function. EndIf WEnd EndFunc Func _ProgressBar($pack) If $pack = 1 Then ProgressOn("CA Single Sign-On", "Sign-On Progress", "0 percent") For $pack = 1 to 20 Step 5 ProgressSet( $pack, $pack & " percent","Checking for the application") sleep(250) Next EndIf If $pack = 20 Then For $pack = 20 to 40 Step 5 ProgressSet( $pack, $pack & " percent","Launching the application") sleep(250) Next EndIf If $pack = 40 Then For $pack = 40 to 60 Step 5 ProgressSet( $pack, $pack & " percent","Waiting for Login dialog.") sleep(250) Next EndIf If $pack = 60 Then For $pack = 60 to 80 Step 5 ProgressSet( $pack, $pack & " percent", "Submittng the Credentials") sleep(250) Next EndIf If $pack = 80 Then For $pack = 80 to 99 Step 5 ProgressSet( $pack, $pack & " percent", "Checking the Login Results.") sleep(250) Next EndIf If $pack = 100 Then ProgressSet(100 , "Done", "Sign-On Complete") sleep(500) ProgressOff() Exit EndIf If $pack > 101 Then ProgressOff() errormsg($pack) EndIf _resetConnection() EndFunc Func _resetConnection() TCPCloseSocket ($ConnectedSocket) ; Closes the socket $ConnectedSocket = -1 ; Resets the ConnectedSocket placeholder $conned = False ; Set the conned var to false (really no use for this... Used it in an older version. will be removed soon.) _waitForConn() ; Go back to the "searching for a connection" function. EndFunc Func errormsg($pack) Switch $pack ;StartScript errors Case 200 $msg = "StartScript Err200-1, Code is incorrect." Case 210 $msg = "StartScript Err210-2, Text was not found." Case 220 $msg = "StartScript Err220-4, Window was not found." Case 230 $msg = "StartScript Err230-6, Text in window not found." Case 240 $msg = "StartScript Err240-20, Window could not be activated." Case 250 $msg = "StartScript Err250-21, Duplicate windows found." Case 260 $msg = "StartScript Err260-80, Application could not be found." Case 270 $msg = "StartScript Err270-99, Program Fault." Case 280 $msg = "StartScript Err280-100, Fatal Error." ;LoginScript Errors Case 300 $msg = "LoginScript Err300-1, Code is incorrect." Case 310 $msg = "LoginScript Err310-2, Text was not found." Case 320 $msg = "LoginScript Err320-4, Window was not found." Case 330 $msg = "LoginScript Err330-6, Text in window not found." Case 340 $msg = "LoginScript Err340-20, Window could not be activated." Case 350 $msg = "LoginScript Err350-21, Duplicate windows found." Case 360 $msg = "LoginScript Err360-80, Application could not be found." Case 370 $msg = "LoginScript Err370-99, Program Fault." Case 380 $msg = "LoginScript Err380-100, Fatal Error." ;LoginResults Errors Case 400 $msg = "LoginResults Err400-1, Code is incorrect." Case 410 $msg = "LoginResults Err410-2, Text was not found." Case 420 $msg = "LoginResults Err420-4, Window was not found." Case 430 $msg = "LoginResults Err430-6, Text in window not found." Case 440 $msg = "LoginResults Err440-20, Window could not be activated." Case 450 $msg = "LoginResults Err450-21, Duplicate windows found." Case 460 $msg = "LoginResults Err460-80, Application could not be found." Case 470 $msg = "LoginResults Err470-99, Program Fault." Case 480 $msg = "LoginResults Err480-100, Fatal Error." ;PasswordExpire Errors Case 500 $msg = "PasswordExpire Err500-1, Code is incorrect." Case 510 $msg = "PasswordExpire Err510-2, Text was not found." Case 520 $msg = "PasswordExpire Err520-4, Window was not found." Case 530 $msg = "PasswordExpire Err530-6, Text in window not found." Case 540 $msg = "PasswordExpire Err540-20, Window could not be activated." Case 550 $msg = "PasswordExpire Err550-21, Duplicate windows found." Case 560 $msg = "PasswordExpire Err560-80, Application could not be found." Case 570 $msg = "PasswordExpire Err570-99, Program Fault." Case 580 $msg = "PasswordExpire Err580-100, Fatal Error." Case Else $msg = "Unknown error has occured." EndSwitch MsgBox(0, "Sign-On Error has occured", $msg) Exit EndFunc updateprogressbar code expandcollapse popup$var1 = $cmdline[1] Opt('MustDeclareVars', 1) Global $pack, $var1 UpdateProgressbar() Func UpdateProgressbar() ; Set Some reusable info ;-------------------------- Local $ConnectedSocket, $szData ; Set $szIPADDRESS to wherever the SERVER is. We will change a PC name into an IP Address ; Local $szServerPC = @ComputerName ; Local $szIPADDRESS = TCPNameToIP($szServerPC) Local $szIPADDRESS = @IPAddress1 Local $nPORT = 65432 $szData = $var1 ; Start The TCP Services ;============================================== TCPStartup() ; Initialize a variable to represent a connection ;============================================== $ConnectedSocket = -1 ;Attempt to connect to SERVER at its IP and PORT 33891 ;======================================================= $ConnectedSocket = TCPConnect($szIPADDRESS, $nPORT) ; If there is an error... show it If @error Then MsgBox(4112, "Error", "TCPConnect failed with WSA error: " & @error) ; If there is no error loop an inputbox for data ; to send to the SERVER. Else ;Loop forever asking for data to send to the SERVER ;While 1 ; InputBox for data to transmit ;$szData = InputBox("Data for Server", @LF & @LF & "Enter data to transmit to the SERVER:") ; If they cancel the InputBox or leave it blank we exit our forever loop ;If @error Or $szData = "" Then ExitLoop ; We should have data in $szData... lets attempt to send it through our connected socket. ;ToolTip("Client: Sending progressbar update."&@CRLF&"Sending Data: " & " " & $var1,10,10) TCPSend($ConnectedSocket, $szData) Sleep(1250) ; If the send failed with @error then the socket has disconnected ;---------------------------------------------------------------- ;If @error Then ExitLoop ;WEnd EndIf EndFunc ;==>Example Help documentation expandcollapse popupUpdateprogress.exe commands Syntax: Updateprogress.exe value (progressbar.exe must be running) ** Warning if your SSO script exits without updating the progressbar, it will stay on the screen until you right click on the icon in the taskbar. ** Possible values: Value Function 1 This is required to start the progress bar, the progress bar will start moving to 20%,and update the text to say "Checking for the application" 20 This will update the progress to start moving from the 20% to 40%, and update the text to say "Launching the application. 40 This will update the progress bar to start moving from 40% to 60%, and update the text to say "Waiting for login dialog 60 This will update the progress bar to start moving from 60% to 80%, and update the text to say "Submitting credentials." 80 This will update teh progress bar to start moving from 80% to 99%, and update the text to say Checking the Logon Results." 100 This will update the progress bar to say 100%, and update the text to say "Sign-On complete" then the progress bar will close. Error Messages: StartScript Procedure Error Messages; 200 StartScript Err200-1, Code is incorrect. 210 StartScript Err210-2, Text was not found. 220 StartScript Err220-4, Window was not found. 230 StartScript Err230-6, Text in window not found. 240 StartScript Err240-20, Window could not be activated. 250 StartScript Err250-21, Duplicate windows found. 260 StartScript Err260-80, Application could not be found. 270 StartScript Err270-99, Program Fault. 280 StartScript Err280-100, Fatal Error. LoginScript Procedure Error Messages; 300 LoginScript Err300-1, Code is incorrect. 310 LoginScript Err310-2, Text was not found. 320 LoginScript Err320-4, Window was not found. 330 LoginScript Err330-6, Text in window not found. 340 LoginScript Err340-20, Window could not be activated. 350 LoginScript Err350-21, Duplicate windows found. 360 LoginScript Err360-80, Application could not be found. 370 LoginScript Err370-99, Program Fault. 380 LoginScript Err380-100, Fatal Error. LoginResults Procedure Error Messages; 400 LoginResults Err400-1, Code is incorrect. 410 LoginResults Err410-2, Text was not found. 420 LoginResults Err420-4, Window was not found. 430 LoginResults Err430-6, Text in window not found. 440 LoginResults Err440-20, Window could not be activated. 450 LoginResults Err450-21, Duplicate windows found. 460 LoginResults Err460-80, Application could not be found. 470 LoginResults Err470-99, Program Fault. 480 LoginResults Err480-100, Fatal Error. Password Expiration Error Messages; 500 PasswordExpire Err500-1, Code is incorrect. 510 PasswordExpire Err510-2, Text was not found. 520 PasswordExpire Err520-4, Window was not found. 530 PasswordExpire Err530-6, Text in window not found. 540 PasswordExpire Err540-20, Window could not be activated. 550 PasswordExpire Err550-21, Duplicate windows found. 560 PasswordExpire Err560-80, Application could not be found. 570 PasswordExpire Err570-99, Program Fault. 580 PasswordExpire Err580-100, Fatal Error. If any value is used above 101 and not defined in the list, the Message box will report "Unknown error has occured" TCL example code: To activate the progress bar in your SSO script you need to execute the progressbar.exe. This will not display anything until you send the first update to the process. The code is waiting for the user to send a value of 1 to activate the progressbar. this can be done as follows; To intialize the progressbar exec progressbar.exe & to activate the progressbar.exe exec updateprogress.exe 1 & (the progressbar will start moving by increments of 5 until it reaches 20) to update the progressbar.exe exec updateprogress.exe 20 & (the progressbar will start moving by increments of 5 until it reaches 40) exec updateprogress.exe 40 & (the progressbar will start moving by increments of 5 until it reaches 60) exec updateprogress.exe 60 & (the progressbar will start moving by increments of 5 until it reaches 80) exec updateprogress.exe 80 & (the progressbar will start moving by increments of 5 until it reaches 99) exec updateprogress.exe 100 & (sets the progressbar to 100 and then after 500ms closes the progressbar) To send the progressbar an error message and close exec updateprogress.exe 200 & Release 1.0 Alpha release (standalone Progress bar) release 1.1 code changes 1. Changed code to increment the progressbar from 1 to 5 increments 2. Changed possible updates to be limited to a min of every 1250ms, prevents process overruns
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