Jump to content

Auto Erase


Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...