Can I make a batch script uninstaller that deletes itself?

I am making some installers for various programs, but would also like to include an uninstaller with them.
I do not want to build the installer with NSIS or Inno Setup. I know they do this automatically, but my installers are SFX archive based.
I know how to make the uninstaller delete the specified files I want removed, but is it at all possible to program it to remove itself after everything else from the program is uninstalled?

2 Answers

You can just make it delete itself with del uninstaller.bat or del "%~f0", where %~f0 represents the full path of the script.

6

dbenham found a clever trick to let a batch file delete itself without errors in this answer on StackOverflow

cite
In summary, (GOTO) 2>NUL behaves like EXIT /B, except it allows execution of concatenated commands in the context of the caller!
So all you need is

(goto) 2>nul & del "%~f0"
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like