Jump to content
Sign in to follow this  
Francisco

Auto Erase

Recommended Posts

Francisco

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 by Francisco

Share this post


Link to post
Share on other sites
weaponx

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=48748

and here: http://www.autoitscript.com/forum/index.ph...c=49674&hl=

Edited by weaponx

Share this post


Link to post
Share on other sites
ssubirias3

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¶êå

Share this post


Link to post
Share on other sites
Francisco

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

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  

×