View Full Version : Remove folder in AppDataFolder during Uninstall

12-16-2013, 10:54 AM
I have Basic MSI project. This is installation package for Windows Forms application.
User installs it, starts working and can store some user settings (for example, form's size, location,...) to xml files located at c:\Users\username\AppData\Roaming\MyProjectNameFolder

I'm trying to implement possibility of removing these setting files during uninstall. For this purpose I added simple checkbox 'Remove user settings' and placed it on ReadyToRemove dialog. Then I created a custom action specifying
cmd.exe /c rmdir /s/q "[AppDataFolder]MyProjectNameFolder" as File Name and Command Line param.

So, it removes MyProjectNameFolder if checkbox checked. But displays 'Error 1722. There's problem with this Windows Installer package....' when I'll trying to invoke this CA if c:\Users\username\AppData\Roaming\MyProjectNameFolder does not exist.

I have a question, what is the best approach in this case? Can installScript and DeleteDir function help me? Or may be it's better do not create InstallScript CA at all, but find correct condition for my Custom Action with cmd and rmdir?

12-16-2013, 04:26 PM
Maybe this would help - it pipes all output it to NUL so it doesn't care if it does or does not find the folder. It also wouldn't care if it found the folder but couldn't delete it, though.

cmd.exe /c rmdir /s/q "[AppDataFolder]MyProjectNameFolder" >NUL 2>&1


12-18-2013, 04:09 AM

It didn't help.I just tried to invoke rmdir with >NUL 2>&1 in the end using windows command line - it works (I mean it doesn't show me a message 'system cannot find the file specified').

But the same command in Installshield's Custom Action

cmd.exe /c rmdir /s/q "[AppDataFolder]MyProjectNameFolder" >NUL 2>&1
still shows me an error dialog when I'm trying to delete folder that does not exist!

So, what's wrong here? Any other ideas?

12-18-2013, 06:20 AM
Do this instead. It only executes the rmdir if the destination exists. This way you will still see other relevant error messages if you do get a real error.

cmd.exe /c if exist "[AppDataFolder]MyProjectNameFolder" rmdir /s /q "[AppDataFolder]MyProjectNameFolder"

12-19-2013, 12:41 AM
If you project type is Basic MSI, you can delete these files through RemoveFile table.

Add two items into RemoveFile table, remove files and empty folder.

12-19-2013, 09:30 AM
Im Using a custum action like

function Removefolder(hMSI)
STRING szPath;
NUMBER supportDirPathBuffer, nReturn, nvResult;

supportDirPathBuffer = MAX_PATH;
MsiGetProperty(hMSI, "CustomActionData", szPath, supportDirPathBuffer);

nReturn = DeleteDir (szPath, ALLCONTENTS);
if (nReturn = 0) then
SprintfMsiLog ( "deleted folder: ",szPath);
SprintfMsiLog ( "Unable to delete folder: %s ; error %d",szPath, nReturn );