tags:

views:

4055

answers:

4

I am new to Inno Setup. Stuck on one issue ~ how to configure the uninstall piece to remove all files, folders, subfolders, and even new files/folders etc. created by application (in other words, a 100% removal of the application and associated files).

I hunted around here and also on their forum, and came up empty. Can anyone point me to a document, FAQ etc. regarding how to do this?

UPDATE

Thanks for all the feedback so far (very awesome). So it looks like I can delete everything using the {app}*.* directive in the uninstall section. Also looks like everyone is advising against it. So the question now becomes (I am wondering if this should be a totally new question) is there a way during the uninstall that we can ask the user 'Do you want to remove all project files associated with this application?' and if they answer YES, to run the uninstall {app}*.* piece?

Thanks -

A: 

Isn't that the default if your don't specify "uninsneveruninstall" for an entry?

edit - Sorry I hadn't realised you were talking about newly created data files.

Martin Beckett
Don't believe so, it should only uninstall files that it created and has no knowledge of what your application would have created. (Someone correct me if I'm wrong)
Davy8
Not sure (again, I am new to Inno Setup), but when I uninstall our application, it leaves any new files created (and consequently, folders the exist in). I believe because of this, the install folder is also not removed. Thanks ~
OneNerd
If I'm not mistaken it only removes files it creates, and only removes the folder if it's empty. This is default for a very good reason (see my answer)
Davy8
+3  A: 

I think the recommended approach is to specify what to remove in the uninstall section. The reasoning is that what if for whatever reason the user decided to put their own files in your installation directory that they didn't want removed, or saved data that they might want to keep around (maybe they uninstall is to install a newer version?)

That being said, I don't know offhand what the script is, but if you use ISTool (highly recommend) just got to the Uninstall Delete section and add things you want removed. It should present all the possible options in a nice GUI and generate the script for you.

Edit: An example from the Inno Setup documentation:

[UninstallDelete]
Type: files; Name: "{win}\MYPROG.INI"

But they strongly you don't do something like

[UninstallDelete]
Type: files; Name: "{app}\*.*"

NOTE: Don't be tempted to use a wildcard here to delete all files in the {app} directory. I strongly recommend against doing this for two reasons. First, users usually don't appreciate having their data files they put in the application directory deleted without warning (they might only be uninstalling it because they want to move it to a different drive, for example). It's better to leave it up to the end users to manually remove them if they want. Also, if the user happened to install the program in the wrong directory by mistake (for example, C:\WINDOWS) and then went to uninstall it there could be disastrous consequences. So again, DON'T DO THIS!

Davy8
Thanks Davy ~ so you are saying there is no way to specify that files added AFTER the installation get deleted?
OneNerd
You can, you just need to tell it what those files or folders are.
Davy8
.. and if I do not know what those file/folders are ahead of time (which I do not), then I assume as Ken White has proclaimed, that there is no way to do that?
OneNerd
Well (I think) you can set tell it to delete the install directory and all files inside it. I'm just saying that it doesn't do it by default and has a good reason not to. Will edit answer with more info.
Davy8
There's a good reason this capability is not recommended. On the other hand, a well-behaved app shouldn't be writing to its install folder either, since that makes it harder to use on Vista or XP by a non-admin user.
RBerteig
+2  A: 

You can't use InnoSetup to uninstall anything it didn't install, and you shouldn't want to do so. I for one would be very unhappy if I installed an application, entered a lot of data, and then decided to use something else instead that would read that data from your app. If your uninstall killed all of the work I'd already done, I might be tempted to come looking for you. And probably not to buy you a cup of coffee.

Or consider the case where I install your application in the process of evaluating several. I try the apps, and keep going back to yours because I like it a little better, and each time I enter more data. Then I decide not to do anything for a while, so I remove all the test apps. In a week, I decide I need to use your app now after all, and I reinstall it. Oops! All of the work I did testing it that I now wanted to use is gone.

The above is why, when you uninstall an application, it leaves behind anything you created in the folders, like configuration files, data files, etc. It doesn't know what you want it to do with them, so it leaves them alone.

Ken White
Technically you can, but you shouldn't. See the [UninstallDelete] section if you think you are fireproof and impervious to pitchfork-wielding angry mobs of users. But really, don't do it. It is there so that an application that leaks things like help index files when running can delete them.
RBerteig
Thanks for the correction. I've never researched it in that depth, as I'm not fireproof and impervious. I'm also not up for being sued if my uninstall deletes something really important to one of my customers. <g>
Ken White
+4  A: 

You should probably have made this a totally new question, but I'll answer your updated question here as well. Have a look at the section "Pascal Scripting: Uninstall Code" in the Inno Setup Documentation.

To give an example how to conditionally delete data files as part of the uninstallation process:

[Code]

procedure DeleteBitmaps(ADirName: string);
var
  FindRec: TFindRec;
begin
  if FindFirst(ADirName + '\*.*', FindRec) then begin
    try
      repeat
        if FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY <> 0 then begin
          if (FindRec.Name <> '.') and (FindRec.Name <> '..') then begin
            DeleteBitmaps(ADirName + '\' + FindRec.Name);
            RemoveDir(ADirName + '\' + FindRec.Name);
          end;
        end else if Pos('.bmp', AnsiLowerCase(FindRec.Name)) > 0 then
          DeleteFile(ADirName + '\' + FindRec.Name);
      until not FindNext(FindRec);
    finally
      FindClose(FindRec);
    end;
  end;
end;

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
  if CurUninstallStep = usUninstall then begin
    if MsgBox('Do you want to delete all data files?', mbConfirmation,
        MB_YESNO) = IDYES 
    then begin
      DeleteBitmaps(ExpandConstant('{app}'));
    end;
  end;
end;

But depending on the amount of stuff you need to clean up you might be better off to create a special helper program that is part of the installation, and which can be executed during the uninstallation of the app (using an entry in the [UninstallRun] section).

mghie
perfect ~ thanks very much!
OneNerd