puthuff Posted December 1, 2008 Posted December 1, 2008 im pretty new to autoit in itself and im making a simple redialer for my aolaccount on the network that i share my internet connection with unfortunately i dont like to get up and manually do it so i made this little script that works fine it just leaves a cmd.exe window open. expandcollapse popup#include <ASock.au3> Const $MYMSG = 1024 Const $PORT2LISTEN = 8558 Global $hNotifyGUI = GUICreate( "notify" ) Global $hListen Global $hAccepted = -1 If Not TCPStartup( ) Then Exit 1 If Not _StartServer( "0.0.0.0", $PORT2LISTEN, "OnEvent" ) Then Exit 2 ConsoleWrite( "+> Waiting for connection on port #" & $PORT2LISTEN & "..." & @CRLF ) While $hAccepted = -1 ; blah blah... WEnd ; Connection accepted! ConsoleWrite( "Connection accepted, socket #" & $hAccepted & @CRLF ) While $hAccepted <> -1 WEnd TCPCloseSocket( $hListen ) TCPShutdown( ) Exit 0 ; This is called when an event has happened on a socket. Func OnEvent( $hWnd, $iMsgID, $WParam, $LParam ) Local $hSocket = $WParam Local $iError = _HiWord( $LParam ) Local $iEvent = _LoWord( $LParam ) Local $sDataBuff If $iMsgID = $MYMSG Then Switch $iEvent Case $FD_ACCEPT If $iError <> 0 Then Exit MsgBox( 16, "simpleServer error", "Failed to listen to " & $PORT2LISTEN & "." ) EndIf $hAccepted = TCPAccept( $hListen ) Case $FD_READ If $iError <> 0 Then TCPCloseSocket( $hAccepted ) $hAccepted = -1 Else $sDataBuff = TCPRecv( $hAccepted, 8192 ) If @error Then TCPCloseSocket( $hAccepted ) $hAccepted = -1 Else If StringInStr($sDataBuff, "disconnect", 0) Then ConsoleWrite( "{{" & $sDataBuff & "}}" & @CRLF ) ; ;TrayTip( "Data has arrived!", $sDataBuff, 30 ) disconnect() Else ConsoleWrite($sDataBuff& @CRLF) EndIf EndIf EndIf Case $FD_WRITE If $iError <> 0 Then TCPCloseSocket( $hAccepted ) $hAccepted = -1 EndIf Case $FD_CLOSE; Bye bye _ASockShutdown( $hAccepted ) Sleep( 1 ) EndSwitch EndIf EndFunc Func _StartServer( $sIP, $iPort, $sFunc ) $hListen = _ASocket( ) If @error Then Return False _ASockSelect( $hListen, $hNotifyGUI, $MYMSG, BitOR( $FD_ACCEPT, $FD_READ, $FD_WRITE, $FD_CLOSE ) ) If @error Then Return False GUIRegisterMsg( $MYMSG, $sFunc ) _ASockListen( $hListen, $sIP, $iPort ) If @error Then Return False Return True EndFunc Func Disconnect() sleep(5) ProcessClose("AOLDial.exe") If ProcessWaitClose("AOLDial.exe") Then ;TrayTip("test","Aol Dialer has been disconnected", 30) ConsoleWrite("Aol connection has been terminated." & @CRLF) $process = 0; EndIf If $process = 0 Then ;TrayTip("test","Aol connection not found. Starting.....", 30) ConsoleWrite("Starting AOL Dialer.exe" & @CRLF) Sleep(5) Run(@ComSpec & " /k " & 'c:\dialer.bat') sleep(1000) WinActivate("AOL Dialer") startDialing() EndIf EndFunc Func startDialing() Sleep(5000) ConsoleWrite("Starting the dial" & @CRLF) WinActivate("AOL Dialer") ControlClick("AOL Dialer", "Sign On", "[CLASS:SC_BUTTON; INSTANCE:3]") EndFunc for some reason i cant call the shortcut or the batch file directly so i have to run it as a dos command but when it finishes running the dos window remains open.
herewasplato Posted December 1, 2008 Posted December 1, 2008 ... the dos window remains open.try changingRun(@ComSpec & " /k " & 'c:\dialer.bat')Run(@ComSpec & " /c " & 'c:\dialer.bat') [size="1"][font="Arial"].[u].[/u][/font][/size]
UltraFine Posted December 1, 2008 Posted December 1, 2008 there is a UDF in example scripts 'INetCon.au3' also search for it.
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