Red Prince
26th February 2003 05:23 UTC
How do I delete a directory after rebooting?
Hello, this is my first post here. First, I would like to express my gratitude for such a nice installer package! Second, I have searched for the answer to my question and did not find it. Here, then, is the question:
I am installing a server that always runs. So, when uninstalling, I use the /REBOOTOK option for the program executable. That works very well. However, I also need to delete the directory the executable is in and, optionally, its parent directory. So I do:
Delete /REBOOTOK $INSTDIR\program.exe
; MUST REMOVE UNINSTALLER, too
Delete $INSTDIR\uninstall.exe
; remove directories used.
RMDir /r "$INSTDIR"
RMDir "$PROGRAMFILES\Company Name"
(The "Company Name" is the parent directory of $INSTDIR). The problem is the directories do not get deleted because program.exe is still running, so it is deleted upon reboot. I tried to specify /REBOOTOK after the RMDir, but the compiler smote me.
If there is a way to have these directories removed on reboot (with the "Company Name" one only if nothing else is left inside it), please let me know.
Thanks,
Adam
Smile2Me
26th February 2003 07:09 UTC
As far as I know, there is no possibility to do this directly. However, you could make a small separate exe that you put in the temp dir at uninstall and let that execute at startup, so put a shortcut in $SMSTARTUP or a regentry in HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run. Then this program could perform some last minute tasks and delete the regentry/shortcut. It cannot delete itself, but since it is in the temp dir it doesn't harm that much and the user will delete himself after some time (when cleaning the comp).
Hope this helps. It has been discussed before (as far as I can remember), but can't find that anymore.
Good luck,
-Hendri.
kichik
26th February 2003 10:44 UTC
RMDir /REBOOTOK is now on the todo list.
Red Prince
26th February 2003 14:30 UTC
Thanks, both of you.
Red Prince
2nd March 2003 01:19 UTC
I ended up with a workaround. Strangely, it works for one program but not for another. They are both running at the time of the uninstall, so there should be no difference.
Anyway, I thought perhaps others might find it useful, so here is what I did:
GetTempfileName $0
Delete $0
Rename "$INSTDIR\foo.exe" $0
Delete /REBOOTOK $0
; If that did not work, delete it from its directory
IfFileExists "$INSTDIR\foo.exe" "" "bar"
Delete /REBOOTOK "$INSTDIR\foo.exe"
bar:
RMDir /r "$INSTDIR"