CarVeR Posted May 2, 2010 Share Posted May 2, 2010 Hi, i am new to AutoIt and i am finding it fascinating to work with. When i say new, i mean i started using it a few days ago. Using somebody's code i have made a script which checks a program for an error window and restarts the program if it finds the window. If it doesnt find the window it sleeps for 15 minutes. Note i did not write the code that does all this, i wrote code which adds a .wav file into the compiled program and extracts it to a particular directory and plays the sound when the error message appears. It all works fine (i think) apart from the OnAutoItExit section. My problem is that it does not display the message boxes and it does not delete the temporary extracted file when i exit the program, i am exiting by right clicking the task bar icon and clicking exit. I am sure i am doing something wrong with OnAutoItExit. Here is my Code: #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_icon=..\Icons\filetype3.ico #AutoIt3Wrapper_outfile=µTorrentRestart.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** FileInstall ("C:\Users\Bob\Documents\TankFiring.wav", "C:\Users\" & @UserName & "\TankFiring.wav" [, 1]) $Continue = True While $Continue = True ; check if the crash dialog exists If WinExists("µTorrent") Then ; play error sound soundplay ( "C:\Users\" & @UserName & "\TankFiring.wav") ; activate the crash dialog $Activate = WinActivate("[TITLE:µTorrent]", "") ; click the ok button $Click = ControlClick ( "µTorrent", "", "OK" ) EndIf Sleep(900000) WEnd Func OnAutoItExit() FileDelete ("C:\Users\" & @UserName & "\TankFiring.wav") If FileExists ("C:\Users\" & @UserName & "\TankFiring.wav") Then MsgBox (0, "TankFiring.wav", "ERROR: Temporary file could not be deleted.") Else MsgBox (0, "TankFiring.wav", "SUCCESS: Temporary file was successfully deleted.") EndIf EndFunc;==> OnAutoItExit() Thank you for reading and helping me. c4rv3r Link to comment Share on other sites More sharing options...
CarVeR Posted May 2, 2010 Author Share Posted May 2, 2010 I have just spotted one error with this line of code: FileInstall ("C:\Users\Bob\Documents\TankFiring.wav", "C:\Users\" & @UserName & "\TankFiring.wav" [, 1]) I've now changed it to: FileInstall ("C:\Users\Bob\Documents\TankFiring.wav", "C:\Users\" & @UserName & "\TankFiring.wav" , 1) That still doesn't affect my problem, i just thought i'd point it out incase anyone noticed. Link to comment Share on other sites More sharing options...
trancexx Posted May 2, 2010 Share Posted May 2, 2010 Add:OnAutoItExitRegister("OnAutoItExit") Function OnAutoItExit is no longer supported by AutoIt. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
CarVeR Posted May 2, 2010 Author Share Posted May 2, 2010 (edited) Thank you for your answer and your quick reply. I was just wondering where would i put this piece of code you have given me? Do i place it before Func and then make Func call "OnAutoItExit" Something like this: WEnd OnAutoItExitRegister("OnAutoItExit") Func OnAutoItExit Sorry if its such a noob question, i really am a big autoit noob =P Edited May 2, 2010 by CarVeR Link to comment Share on other sites More sharing options...
CarVeR Posted May 2, 2010 Author Share Posted May 2, 2010 (edited) Right i know how to do it now. I just looked at the syntax of OnAutoItExitRegister. My code now: (it should work) OnAutoItExitRegister("OnAutoItExit") Func OnAutoItExit() Thank you for your help trancexx Edited May 2, 2010 by CarVeR Link to comment Share on other sites More sharing options...
GEOSoft Posted May 2, 2010 Share Posted May 2, 2010 Right i know how to do it now. I just looked at the syntax of OnAutoItExitRegister. My code now: (it should work) OnAutoItExitRegister("OnAutoItExit") Func OnAutoItExit() Thank you for your help trancexx You should really put the OnAutoItExitRegister("OnAutoItExit") at or near the top of the script. Do you have the link to where you found that script? If so please post it so one of us can fix it and repost the corrected code. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
CarVeR Posted May 2, 2010 Author Share Posted May 2, 2010 (edited) You should really put the OnAutoItExitRegister("OnAutoItExit") at or near the top of the script. Do you have the link to where you found that script? If so please post it so one of us can fix it and repost the corrected code. This is a link to the uTorrent section of the code. All of the other bits of code i wrote myself. Link: http://forum.utorrent.com/viewtopic.php?pid=350635 Full Code: #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_icon=..\Icons\filetype3.ico #AutoIt3Wrapper_outfile=µTorrentRestart.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** OnAutoItExitRegister("OnAutoItExit") FileInstall ("C:\Users\Bob\Documents\TankFiring.wav", "C:\Users\" & @UserName & "\TankFiring.wav" ,1) $Continue = True While $Continue = True ; check if the crash dialog exists If WinExists("µTorrent") Then ; play error sound soundplay ( "C:\Users\" & @UserName & "\TankFiring.wav") ; activate the crash dialog $Activate = WinActivate("[TITLE:µTorrent]", "") ; click the ok button $Click = ControlClick ( "µTorrent", "", "OK" ) EndIf Sleep(900000) WEnd Func OnAutoItExit() If FileExists ("C:\Users\" & @UserName & "\TankFiring.wav") Then FileDelete ("C:\Users\" & @UserName & "\TankFiring.wav") EndIf If FileExists ("C:\Users\" & @UserName & "\TankFiring.wav") Then MsgBox (0, "TankFiring.wav", "ERROR: Temporary file could not be deleted.") Else MsgBox (0, "TankFiring.wav", "SUCCESS: Temporary file was successfully deleted.") EndIf EndFunc Your suggestion of putting the Code at the beginning of the script worked perfectly! The script is fully working now. Thank you very much GEOSoft. Edited May 2, 2010 by CarVeR Link to comment Share on other sites More sharing options...
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