- NSIS Discussion
- Delete Files and Directory not working
Archive: Delete Files and Directory not working
stonkers
5th April 2004 17:34 UTC
Delete Files and Directory not working
I'm having problems getting files and directory deleted. My Uninstall routine is:
_________________________________
Section Uninstall
;Delete Files
Delete "$INSTDIR\*.*"
;Delete Uninstaller And Unistall Registry Entries
Delete "$INSTDIR\Uninst.exe"
DeleteRegKey HKEY_LOCAL_MACHINE "SOFTWARE\MyApp"
DeleteRegKey HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MyApp"
RMDir /r "$INSTDIR"
__________________________________
After the Uninstall method is run, the $INSTDIR including all subdirectories and files is still there. Any help?
Thanks,
Eric
Joost Verburg
5th April 2004 19:14 UTC
* Is the uninstaller located in the directory you want to delete?
* Is the directory not in use? Can you delete it manually?
stonkers
5th April 2004 23:28 UTC
Uninstaller should no longer be there by the point in the code where it should be deleting the directory. I have no problems deleting the directory manually.
VegetaSan
5th April 2004 23:36 UTC
Try this :
Section Uninstall
Delete "$INSTDIR\*.*"
Delete "$INSTDIR\Uninst.exe"
DeleteRegKey HKLM "SOFTWARE\MyApp"
DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MyApp"
RMDir /r "$INSTDIR"
stonkers
6th April 2004 16:12 UTC
I'm confused by your reply Vegetasan. I'm not having problems with the registry. The problem I'm having is with:
RMDir /r "$INSTDIR"
The installer recognizes when the app is already installed... Can you give me more info on this change if I'm not understanding?
Thanks,
Eric
VegetaSan
6th April 2004 16:38 UTC
No I just set it between the script like you
Your script
Section Uninstall
;Delete Files
Delete "$INSTDIR\*.*"
;Delete Uninstaller And Unistall Registry Entries
Delete "$INSTDIR\Uninst.exe"
DeleteRegKey HKEY_LOCAL_MACHINE "SOFTWARE\MyApp"
DeleteRegKey HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MyApp"
RMDir /r "$INSTDIR"
So I did it like you. But without the registry:
Delete "$INSTDIR\*.*"
Delete "$INSTDIR\Uninst.exe"
RMDir /r "$INSTDIR"
Just try this one and say if it works
Joost Verburg
6th April 2004 17:08 UTC
That will make no difference. Are you sure $INSTDIR is correct?
stonkers
6th April 2004 21:50 UTC
Joost,
Here's the entire script. Looks to me like it would be right, but I'm not positive. See a problem?
______________________________________
;NSIS Script
;Backgound Colors
BGGradient 800080 000000 FFFFFF
BrandingText " "
;Title Of Your Application
Name "MyApp"
;Do A CRC Check
CRCCheck On
;Included file(s)
!include servicelib.nsh
;Output File Name
OutFile "InstallMyApp.exe"
;The Default Installation Directory
InstallDir "D:\Program Files\MyApp"
;The text to prompt the user to enter a directory
DirText "Please select the folder below"
Section "Install"
;Install Files
SetOutPath $INSTDIR
SetCompress Auto
SetOverwrite IfNewer
File /r "D:\projects\MyApp\*.*"
; Write the uninstall keys for Windows
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\MyApp" "DisplayName" "MyApp (remove only)"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\MyApp" "UninstallString" "$INSTDIR\Uninst.exe"
WriteUninstaller "Uninst.exe"
SectionEnd
Section "Shortcuts"
;Add Shortcuts
SectionEnd
UninstallText "This will uninstall MyApp from your system"
Section Uninstall
;Delete Files
Delete "$INSTDIR\*.*"
;Delete Uninstaller And Unistall Registry Entries
Delete "$INSTDIR\Uninst.exe"
DeleteRegKey HKEY_LOCAL_MACHINE "SOFTWARE\MyApp"
DeleteRegKey HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MyApp"
RMDir /r "$INSTDIR"
SectionEnd
;--------------------------------
;Installer Functions
Function .onInit
ReadRegStr $R0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\MyApp" "UninstallString"
StrCmp $R0 "" done
MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
"MyApp is already installed. $\n$\nClick `OK` to remove the \
previous version or `Cancel` to cancel this upgrade." \
IDOK uninst
Abort
;Run the uninstaller
uninst:
ClearErrors
ExecWait '"$R0" _?=$INSTDIR' ;Do not copy the uninstaller to a temp file
done:
FunctionEnd
Joost Verburg
6th April 2004 22:09 UTC
Are you running the uninstaller manually and in the right directory?
Is there a possible problem with user rights?
stonkers
6th April 2004 22:56 UTC
No, I don't run it manually. The executable asks me if I want to uninstall and I say yes. Are you saying that the "Uninstall" section won't get run? Sorry, it's been quite a while since I created these scripts.
I'm administrator on all the machines that I'm installing on.
Joost Verburg
7th April 2004 16:52 UTC
So what happends when you start the uninstaller manually? Are the installation directories of the installer and uninstaller equal?
stonkers
7th April 2004 22:28 UTC
Hmmmmmmm. If I run the uninstaller manually, it works fine. The log shows it deleting the folder and it does. However, when I run the installer and do uninstall first, it doesn't even show the line being executed (as if it doesn't exist). Obviously something is wrong in my code. Any clue?
stonkers
7th April 2004 22:39 UTC
So when I run the installer manually, I see output from the entire thing running. When I run the uninstaller from the installer, it does everything except for the rmdir. In other words:
Delete "$INSTDIR\*.*"
does happen and the app gets unregistered. I'm REALLY lost!
Joost Verburg
8th April 2004 13:13 UTC
What is the value of $INSTDIR in the uninstaller? You are setting it using the command line, make sure that the installer $INSTDIR is the folder to uninstall from.
stonkers
9th April 2004 16:23 UTC
$INSTDIR has to be correct because the lines:
Delete "$INSTDIR\*.*"
and
Delete "$INSTDIR\Uninst.exe"
are deleting from the correct place; the directory that I want to delete with:
RMDir /r "$INSTDIR"
Which doesn't even get attempted based on the log.
stonkers
9th April 2004 17:23 UTC
I hard coded the path to delete:
RMDir /r "D:\MyApp"
and got the same results. The uninstaller doesn't even attempt to perform the command. Do I need to put the delete of the uninstaller after my RMDir?
Joost Verburg
9th April 2004 20:31 UTC
And does it make any difference whether you start it manually or not?
stonkers
10th April 2004 02:33 UTC
It always works when I start it manually which makes no sense to me.
stonkers
13th April 2004 20:48 UTC
Bump
Joost Verburg
13th April 2004 22:19 UTC
You can submit a bug report at the project page. Also attach a script that reproduces the bug and nothing else (no registry entries, files etc.).
kichik
15th April 2004 16:09 UTC
When you start it from the installer directory itself, it can't delete itself. RMDir /R stops if it can't delete one of the files and therefore you are left with more than just the uninstaller. Simply copy the uninstaller somewhere else just like it does on its own when executed without the _?= switch.
stonkers
15th April 2004 23:11 UTC
So if I take out the _?= switch, I should be fine?
Joost Verburg
15th April 2004 23:49 UTC
Yes, but the installer won't wait for the uninstaller to finish.
stonkers
16th April 2004 20:59 UTC
I'm not sure what you mean by copy it somewhere else. Do you mean to have it run from a different place in the first place or move it before doing the RMDIR? How about if I use the Rename command just before the RMDIR? Sorry, I'm very green with this...
kichik
16th April 2004 21:02 UTC
Copy the uninsatller somewhere else before you execute it. For example, the temporary directory ($TEMP).
stonkers
16th April 2004 21:43 UTC
OK, I tried this. I must be doing something wrong. Here's what I changed:
---------------------------------
Before
---------------------------------
;Run the uninstaller
uninst:
ClearErrors
ExecWait '"$R0" _?=$INSTDIR' ;Do not copy the uninstaller to a temp file
---------------------------------
After
---------------------------------
ClearErrors
CopyFiles /SILENT /FILESONLY "$INSTDIR\Uninst.exe" "$TEMP\Uninst.exe"
ExecWait '"$TEMP\Uninst.exe" _?=$INSTDIR'
---------------------------------
Am I missing something else? I apologize if I'm being dense!
stonkers
16th April 2004 21:50 UTC
Please excuse the double post, I used Quick Reply and it doesn't seem to update the "Last Post" information. Please see my previous post. Thanks - Eric
kichik
16th April 2004 21:54 UTC
Are you sure $R0 is "$INSTDIR\Uninst.exe"? Other than that, it looks ok.
stonkers
16th April 2004 22:06 UTC
Part of my change was to quit using $R0. I'm running the Uninst.exe from where I copy it to now:
CopyFiles /SILENT /FILESONLY "$INSTDIR\Uninst.exe" "$TEMP\Uninst.exe"
ExecWait '"$TEMP\Uninst.exe" _?=$INSTDIR'
so that the uninstaller doesn't keep a hold on that directory keeping me from deleting it. Seems like it should work to me, but doesn't execute the RMDIR command still.
kichik
16th April 2004 22:10 UTC
So the uninstaller is executed but nothing is deleted? Can you attach a minimal complete example so I can test this on my own computer and see what's wrong?
stonkers
16th April 2004 22:42 UTC
This is so frustrating. I ripped out the substance and it works fine. I didn't change my Uninstall functionality at all. I'm taking a break from this. Thanks for trying!
stonkers
16th April 2004 22:50 UTC
Well, one difference I found when compiling with substance vs. without substance. When I build the one that doesn't work, I get the warnings:
2 warnings:
uninstall function "un.Service" not referenced - zeroing code (0-278) out
install function "Service" not referenced - zeroing code (0-278) out
Could this have something to do with it?
kichik
16th April 2004 22:55 UTC
No, that only means those functions were not used and were therefore deleted from the output.
Maybe if you can attach both the working script and the script that doesn't work I can spot the difference.
MysticHead
25th February 2005 16:44 UTC
Did anything every happen with this? I'm also trying to get an unistaller to run prior to installing new (updated)files and it doesn't seem to be working. I was just curious if there was something very specific in Stonkers script, or a more general error that might apply to my situation as well.
thanks,
-marc
kichik
25th February 2005 20:27 UTC
As there was no other response from stonkers, the issue was never resolved. Looking at it again, it seems $INSTDIR was simply not initialized with the correct value in .onInit in his last attempt (no InstallDirRegKey in the big script above). I think his issue is pretty specific to his script. If you have a problem with calling the uninstaller, open up another thread with more details.