How to force an Uninstall.exe to delete itself

Article:HOWTO4342  |  Created: 2006-07-20  |  Updated: 2006-07-31  |  Article URL
Article Type
How To

How do I force an uninstall.exe to delete itself?

Have you ever created your own uninstall.exe file, but could not determine how to make it delete itself?  It’s a common problem. Although it might sound easy to solve, the problem is complicated by the fact that you cannot delete a file that is in use. With your uninstall.exe running, how can it delete itself? This article gives you the answer and also provides the code to accomplish the task. The solution for forcing a customized uninstall.exe file to delete itself is to create logic in your uninstall which copies the file to a temporary location then executes it.  The exact code to append to your uninstall file is provided below. You can modify the code to meet your specific uninstall needs, but you must include the actions in this code in the sequence listed.

Rem This is a sample script; you must include similar logic in your custom uninstall.


Rem This procedure forces the customuninstall.exe to delete itself.

Check free disk space.


Rem Performing a check to see if customuninstall.exe has already executed.

Rem Note that the constinstall is a parameter that is passed in the Else section of this code.


If CMDLINE Equals "constinstall" then  


Rem Retrieve the path of Unwise.exe and the install.log.  

Get Registry Key Software\Microsoft\Windows\Explorer\Uninstall place in Variable UNINSTPATH  


Rem Execute Unwise.exe.  

Rem This performs the standard uninstall and deletes the customuninstall.exe.

Execute %UNINSTPATH%\unwise.exe %UNINSTPATH%\install.log  


Rem Force the install to exit.  

Exit Installation  


Rem If the customuninstall.exe has not run itself, then this code is executed.



Rem Get a temp name for the customuninstallexe.

Rem Note that the temporary file has a .tmp extension.

Get Temporary Filename into TEMPFILE  


Rem Retrieve the path of the customuninstall.exe.  

Get System Information into EXELOC  


Rem Parse the .tmp extension from the temporary filename.  

Parse String "%TEMPFILE%" into TEMPFILENAME and EXT  


Rem Append the .exe extension to the temp filename so that the custom uninstall program can be executed.  



Rem Copy the customuninstall.exe to a temp location using the temp filename.  

Copy local file from %EXELOC% to %TEMP%\%CUSTOMUNINST%  


Rem Execute the customuninstall.exe.  

Rem NOTE: Remember to pass the customuninstall.exe a command line parameter.    


Rem This parameter is used as a flag to indicate that the customuninstall.exe has executed.        

Execute %TEMP%\%CUSTOMUNINST% constinstall  


Rem Force the installation to exit.  

Exit Installation  


Rem This is the end of the IF statement.



When you create a customized uninstall, you want to force the installation to remove itself.  You can do this using the uninstall code in this article, which you can append to your uninstall.exe file. If you follow this uninstall code to generate a temp file and copy your uninstall.exe to the %TEMP% location, then Windows deletes the custom uninstall file for you.  The result is a uninstall.exe that deletes itself and requires no further intervention on your part.

Legacy ID


Article URL

Terms of use for this information are found in Legal Notices