Showing results for 
Show  only  | Search instead for 
Did you mean: 
Level 3

Remove folder in AppDataFolder during Uninstall

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?
Labels (1)
0 Kudos
(5) Replies
Level 7

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.

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

0 Kudos
Level 3


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
[CODE]cmd.exe /c rmdir /s/q "[AppDataFolder]MyProjectNameFolder" >NUL 2>&1[/CODE]
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?
0 Kudos
Level 13

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.
[CODE]cmd.exe /c if exist "[AppDataFolder]MyProjectNameFolder" rmdir /s /q "[AppDataFolder]MyProjectNameFolder"[/CODE]
0 Kudos
Not applicable

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.
0 Kudos
Level 4

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 );
0 Kudos