Sorry, I can't give you the final dll, but the working part of it.
My solution consists of 3 parts:
1. I use a custom action to call a c# dll which I pass a maintenance flag.
2. the flag is a populated in a custom action, too. (property set with formatted). For me it is always needed.
in execution stage condition, everything is checked and I put this code into the Condition field, to get maintenance and MSPs, too:
Code: Select all
MSIPATCHREMOVE OR AI_PATCH OR PATCH OR REINSTALL OR AI_MAINT
3. in C# it is the default implementation needed for AI among other things I need to do. The functional part boils down to:
- build a pattern for the appdata path for xp or win 7
- iterate all users in appdata and delete the folder you are looking for.
Code: Select all
/// <summary>
/// deletes the config files from %APPDATA%\MyFolder for each user on the machine
/// </summary>
public void DeleteAppDataFiles()
{
string baseUserFolder, templateAppdata;
GetAppDataMyFolderPath(out baseUserFolder, out templateAppdata);
var users = Directory.GetDirectories(baseUserFolder);
foreach (var userPath in users)
{
try
{
string myFolderPath = userPath + templateAppdata + "\\MyFolder";
if (Directory.Exists(myFolderPath))
{
Directory.Delete(myFolderPath, true);
}
}
catch (Exception ex)
{
Logging.WriteLogEntry(System.Diagnostics.EventLogEntryType.Error, ex.ToString());
}
}
}
private void GetAppDataMyFolderPath(out string baseUserFolder, out string templateForAppDataPath)
{
string appdataFolder = Environment.ExpandEnvironmentVariables("%APPDATA%");
// results in
// "C:\Documents and Settings\<username>\Application Data" on XP
// "C:\Users\<username>\AppData\Roaming" on Vista or above
//from start to second \
int scndBackslash = appdataFolder.IndexOf("\\", 5, StringComparison.Ordinal);
baseUserFolder = appdataFolder.Substring(0, scndBackslash);
//get rid of C:\Users\<username>
//cant use Environment.UserName to replace, as it may be SYSTEM while in %APPDATA% is current user
templateForAppDataPath = appdataFolder.Substring(
appdataFolder.IndexOf("\\", scndBackslash + 1, StringComparison.Ordinal));//start at third \
}
hope it helps

FOLLOW US
Get the latest news in Application Packaging