Most software packages written for Windows have an uninstall facility. However, there is no easy way to delete files that may already be open. The purpose of WipeDir is to facilitate the development of uninstall methods for small applications by allowing directories containing open files to be deleted as cleanly as possible.
The typical problem when uninstalling an application called GeeWhizz is that because the uninstall program itself is open (\program files\GeeWhizz\uninst.exe) it prevents the directory from being deleted. In this instance, provided the file wipedir.exe is located in the GeeWhizz directory, removal of the directory is achieved by the command wipedir /self.
How do I use WipeDir?
The WipeDir package includes two programs being wipedir.exe and wipedirC.exe. The first is a standard GUI Windows program. The second as a console version for use in batch files. Both versions must be called with command-line parameters - the user is not prompted for a directory to delete.
wipedir FullDirName [switches]
|or, for console use|
wipedirC FullDirName [switches]
|- used as an alternative to a directory name.|
|- requires no user interaction.|
|- fail if unable to delete dir without restarting Windows.|
|- display a Windows progress dialog (GUI version only).|
|- do not check existence of file wipedir.ini|
Before attempting to delete a directory, the existence of the file wipedir.ini is checked.
If this file does not exist :-
- the directory is not deleted.
- the Windows error message "ACCESS DENIED" is displayed.
This feature is intended to prevent accidental deletion of files during development and testing.
Keep the file wipedir.ini in an otherwise empty directory. Include it when building an installation package. This should ensure accidental deletion of files is prevented but sensible backup protocols are always advisable. Also see switches.
WipeDir attempts to delete the required directory using the Windows API function SHFileOperation.
- If the delete operation fails, the WipeDir program sleeps for one second and tries again.
- Up to five retries are made sleeping for one second between each.
- If the final attempt fails, unless the /NoRestart switch is used, WipeDir will cause the directory to be deleted when Windows is restarted.
- The user is informed if a restart is required but WipeDir does not initiate a restart.
When the /self switch is used :-
- WipeDir copies itself to a temporary directory.
- The temporary copy is called with the required parameters to delete the directory containing the original copy.
- The original copy terminates immediately.
- The temporary copy is deleted when Windows is next restarted.
How are directories deleted on restart?
A command is saved in the Windows Registry. The command is run automatically (and deleted) when Windows is next restarted. The table below lists the registry key and the required command.
- The value name used in the registry key is unimportant.
- WipeDir always uses the short form of a directory name (8.3 format).
cmd.exe /C RD /S /Q DirName
COMMAND.COM /C DELTREE.EXE /Y DirName
wipedir %Temp%\GeeWhizzInstaller /noconfirm wipedirC -norestart -noconfirm "C:\Program Files\GeeWhizz" "C:\Program Files\GeeWhizz\wipedir" /self /showprogress
- The directory name may include environment vars.
- The directory name must include a drive root (after environment vars are expanded).
- If the directory name includes spaces, it must be enclosed within quotes.
- Switches may be prefixed either with the / or - (forward slash or hyphen) characters.
- Switches ARE NOT case sensitive and they may appear in any order, before or after the directory name.
- To issue the command, you must use one of the following Windows API functions
CreateProcess - you MUST close the returned thread and process handles. ShellExecute - recommended ShellExecuteEx - DO NOT specify the flag SEE_MASK_NOCLOSEPROCESS.