Francisco Posted August 21, 2007 Share Posted August 21, 2007 (edited) It would like to contribute with a function that I write, 'auto erase' function. It would like to know if somebody has some idea of as to perfect this function Or if it has some criticizes It initiates an archive 'bat' that run hidden. As soon as the program is finished, this archive bat erases the program and self-erases. Sorry my bad english. Func AutoApagar() If Not IsDeclared("arquivo") Then Dim $arquivo If Not IsDeclared("file") Then Dim $file $arquivo = "apagar.bat" FileDelete ($arquivo) $file = FileOpen($arquivo, 1) FileWrite($file, "del " & chr(34) & @ScriptFullPath & chr(34) & @CRLF) FileWrite($file, "if exist " & chr(34) & @ScriptFullPath & chr(34) & " " & $arquivo & @CRLF) FileWrite($file, "if not exist " & chr(34) & @ScriptFullPath & chr(34) & " attrib -r -a -s -h " & chr(34) & $arquivo & chr(34) & " | attrib -r -a -s -h " & chr(34) & $arquivo & chr(34) & @CRLF) FileWrite($file, "if not exist " & chr(34) & @ScriptFullPath & chr(34) & " attrib -r -a -s -h " & chr(34) & $arquivo & chr(34) & " | del " & chr(34) & $arquivo & chr(34) & @CRLF) FileClose($file) FileSetAttrib( $arquivo , "+RASH") Run($arquivo, "", @SW_HIDE) EndFunc Edited August 21, 2007 by Francisco Link to comment Share on other sites More sharing options...
mrbond007 Posted August 21, 2007 Share Posted August 21, 2007 you don't need to use a batch file to delete files, because AutoIt is capable of delete them ex: If FileExists("file1.txt") then FileDelete("file1.txt") .... Projects : Space Regain - Memory Fusion - PWGT - Chip-ITGames : BrainPain - BrainPain Director's Cut - ProSpeed Games Pack (New)Vista vs XP : the forbidden fight Link to comment Share on other sites More sharing options...
weaponx Posted August 21, 2007 Share Posted August 21, 2007 (edited) He means self-destruct the script which has been covered extensively:My version adds an event to the task scheduler to delete whatever you want out of the working directory 1 minute later:#Include RunWait ("at " & _DateTimeFormat ( _DateAdd( 'n',1, _NowCalc()), 4) & ' cmd /c del "' & @ScriptDir & '\*.exe"' )Posted a while back: http://www.autoitscript.com/forum/index.php?showtopic=48748and here: http://www.autoitscript.com/forum/index.ph...c=49674&hl= Edited August 21, 2007 by weaponx Link to comment Share on other sites More sharing options...
ssubirias3 Posted August 21, 2007 Share Posted August 21, 2007 He means self-destruct the script which has been covered extensively: My version adds an event to the task scheduler to delete whatever you want out of the working directory 1 minute later: #Include RunWait ("at " & _DateTimeFormat ( _DateAdd( 'n',1, _NowCalc()), 4) & ' cmd /c del "' & @ScriptDir & '\*.exe"' )oÝ÷ Øú,µçZÂ¥y¶êå Link to comment Share on other sites More sharing options...
Francisco Posted August 21, 2007 Author Share Posted August 21, 2007 I can be wrong, but it would not be better of this form? Func _SelfDelete($iDelay = 0) Local $arquivo Local $conteudo_arquivo $arquivo = @TempDir & "\apagar.bat" FileDelete($arquivo) $conteudo_arquivo = 'ping -n ' & $iDelay & ' 127.0.0.1 > nul' & @CRLF _ &':loop' & @CRLF _ & 'del "' & @ScriptFullPath & '"' & @CRLF _ & 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _ & 'attrib -r -a -s -h "' & $arquivo & '"' & @CRLF _ & 'del "' & $arquivo & '"' FileWrite($arquivo, $conteudo_arquivo) FileSetAttrib( $arquivo , "+RASH") Run($arquivo, @TempDir, @SW_HIDE) EndFunc 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