Jump to content

Can an AU3 compiled EXE-file delete itself?


 Share

Recommended Posts

Moin, moin...! :lmao:

Is there a possibility that a compiled EXE-file deletes itself after its execution?

I would like to write an uninstallation routine for a program, which does not leave any remainders on the harddisk, therefore the Uninstall.exe must delete itself and the including directory. Is that possible?

Thank you for help.

Greets Rudika

[font="Comic Sans Ms"][center]Powered by AutoIt3http://www.wik-eric.de/zips/Synchro2.2.2-4free.zip[/center][/font]

Link to comment
Share on other sites

  • Developers

Moin, moin...! :lmao:

Is there a possibility that a compiled EXE-file deletes itself after its execution?

I would like to write an uninstallation routine for a program, which does not leave any remainders on the harddisk, therefore the Uninstall.exe must delete itself and the including directory. Is that possible?

Thank you for help.

Greets Rudika

posted a long time ago by ?? and is part of the abbrevs in SciTE:

Func _SelfDelete($iDelay = 0)
    Local $sCmdFile
    FileDelete(@TempDir & "\scratch.bat")
    $sCmdFile = 'ping -n ' & $iDelay & '127.0.0.1 > nul' & @CRLF _
            & ':loop' & @CRLF _
            & 'del "' & @ScriptFullPath & '"' & @CRLF _
            & 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _
            & 'del ' & @TempDir & '\scratch.bat'
    FileWrite(@TempDir & "\scratch.bat", $sCmdFile)
    Run(@TempDir & "\scratch.bat", @TempDir, @SW_HIDE)
EndFunc

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

posted a long time ago by ?? and is part of the abbrevs in SciTE:

Func _SelfDelete($iDelay = 0)
    Local $sCmdFile
    FileDelete(@TempDir & "\scratch.bat")
    $sCmdFile = 'ping -n ' & $iDelay & '127.0.0.1 > nul' & @CRLF _
            & ':loop' & @CRLF _
            & 'del "' & @ScriptFullPath & '"' & @CRLF _
            & 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _
            & 'del ' & @TempDir & '\scratch.bat'
    FileWrite(@TempDir & "\scratch.bat", $sCmdFile)
    Run(@TempDir & "\scratch.bat", @TempDir, @SW_HIDE)
EndFunc

~Works fine for me :lmao:

I guess this answers your question rudika. lol.

Edited by CHRIS95219
Link to comment
Share on other sites

  • Developers

All That? Why not just do this?

Func DeleteSelf()
    RUn(@ComSpec & " /k del " & FileGetShortName(@ScriptFullPath), @ScriptDir, @SW_HIDE)
EndFunc

~Works fine for me :lmao:

I guess this answers your question rudika. lol.

Did you try a compiled version ?

Don't think you can DEL a running program..

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Hi,

your version doesn't work. That is why there is the selfdelete func.

Try this: <-- will not work.

HotKeySet("1", "end")

while 1
    Sleep(1000)
WEnd

Func end()
    MsgBox(0,"","SelfDelete")
    Run(@ComSpec & " /k del " & FileGetShortName(@ScriptFullPath), @ScriptDir, @SW_HIDE)
EndFunc   ;==>end

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

  • Developers

Yeah, i did it with both compiled and uncompiled. It works just fine. Have you tried it?

This seems to work pretty good....

But any time the programs takes too long to close down , it will not be deleted...

sleep(50)
Func OnExitFunc()
    
RUn(@ComSpec & " /k del " & FileGetShortName(@ScriptFullPath), @ScriptDir, @SW_HIDE)
EndFunc
Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Administrators

Depends on the speed of your machine. Run() starts...and there is a chance that script will exit before the Run() command actually gets to work. If so it will work. For most people it won't.

Link to comment
Share on other sites

Depends on the speed of your machine. Run() starts...and there is a chance that script will exit before the Run() command actually gets to work. If so it will work. For most people it won't.

I´ll thank you everybody.

Correctly, Jon...

I have both tested variants, however only the suggestion of JdeB is practicable, but I have still modified somewhat, so that it delete the whole directory.

But I don´t really understand the ping...

Func _SelfDelete($iDelay = 0)
    Local $sCmdFile
    FileDelete(@TempDir & "\scratch.bat")
    $sCmdFile = 'ping -n ' & $iDelay & '127.0.0.1 > nul' & @CRLF _
            & ':loop' & @CRLF _
            & 'rd /s /q "' & @ScriptDir & '"' & @CRLF _
            & 'if exist "' & @ScriptDir & '" goto loop' & @CRLF _
            & 'del ' & @TempDir & '\scratch.bat'
    FileWrite(@TempDir & "\scratch.bat", $sCmdFile)
    Run(@TempDir & "\scratch.bat", @TempDir, @SW_HIDE)
EndFunc

So it works like I wanted. :lmao:

Greets Rudika

Edited by rudika

[font="Comic Sans Ms"][center]Powered by AutoIt3http://www.wik-eric.de/zips/Synchro2.2.2-4free.zip[/center][/font]

Link to comment
Share on other sites

I´ll thank you everybody.

Correctly, Jon...

I have both tested variants, however only the suggestion of JdeB is practicable, but I have still modified somewhat, so that it delete the whole directory.

But I don´t really understand the ping...

Func _SelfDelete($iDelay = 0)
    Local $sCmdFile
    FileDelete(@TempDir & "\scratch.bat")
    $sCmdFile = 'ping -n ' & $iDelay & '127.0.0.1 > nul' & @CRLF _
            & ':loop' & @CRLF _
            & 'rd /s /q "' & @ScriptDir & '"' & @CRLF _
            & 'if exist "' & @ScriptDir & '" goto loop' & @CRLF _
            & 'del ' & @TempDir & '\scratch.bat'
    FileWrite(@TempDir & "\scratch.bat", $sCmdFile)
    Run(@TempDir & "\scratch.bat", @TempDir, @SW_HIDE)
EndFunc

So it works like I wanted. :lmao:

Greets Rudika

The ping is to keep the program running. That way your program closes before the command "del" is ever executed.
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...