Sign in to follow this  
Followers 0
bshoenhair

Performing Tasks Before Closing ?

7 posts in this topic

Before a script is closed by windows shutdown or manually by the user, is there a way make it perform actions before it closes ?

Like deleting a log file it was using ?

Share this post


Link to post
Share on other sites



make a clean up funtion and call that instead of a normal exit, or even make a clean up executable installed inside, to cleanup when it finds the main program has ended.

; blah blah blah code
filewriteline("temp_1.txt","Hi I am a line")
; more code
msgbox(1,"ending",filereadline("temp_1.txt",1))
exitnow()
;optional code



func exitnow()
filedelete("temp_1.txt")
exit
endfunc

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

make a clean up funtion and call that instead of a normal exit, or even make a clean up executable installed inside, to cleanup when it finds the main program has ended.

But if the the script is terminated by the windows shutdown the clean up executable might be closed before it does its job.

Maybe I don't quite understand.

I have a script that performs tasks based on HotKeys and is open all the time. This script writes log files that it uses for different tasks. What I want it to do before it closes, which could be forceibly by a user or by the windows shutdown, is to delete these log files. I am only familiar with VB and would use the Form_Unload or the Form_Terminate to perform these tasks. Is there anyway inside an Autoit script to do this ?

Share this post


Link to post
Share on other sites

if you are that worried about the log files, you could just keep them only in memory, or you could have them in a protected filefolder (Write but not Read access.)

No program would work flawlessly, as they could always just pull the powercord.


AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

you could just keep them only in memory

That sounds great.

Basicly I writelines into log files the Read the lines when needed. Please show me how to Writelines into memory Then Readlines from memory when I need to .

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

hotkeyset("{pause}","tellme")
hotkeyset("!{pause}","newline"); hit alt pause to make log file
$x=""; Start with Blank memory variable

while 1
sleep(10); keep computer usage down
wend

func tellme()
msgbox(1,"info",$x); you could send to file if you want, but this is just to show ya
endfunc

func newline()
$x=$x & @crlf & "[LOGFILE] "&@hour&":" & @min &"-"& @sec ; adds this line to $x
endfunc

edit, if you want individual lines, just use something like this to spit back out an array.

$ArrayOfX=Stringsplit(StringReplace($x,@LF,""),@CR) ; I use this on many many examples.

Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

You might find an application called Last Chance helpfull. It is freeware, and will intercept a windows shutdown request (reboots too) and run user specified programs. It will only shut down once those specified programs have finished running.


[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0