I tried to delete a folder at uninstall but it does nothing. specifying the path though, get it to work. Not working:
public void OnAfterInstall(SetupEventArgs e)
{
if (e.IsUninstalling)
{
DirectoryInfo dir = new DirectoryInfo(@"CommonAppDataFolder\myFolder");
if ((bool)(dir?.Exists))
{
dir?.Delete(true);
}
}
}
Working:
public void OnAfterInstall(SetupEventArgs e)
{
if (e.IsUninstalling)
{
DirectoryInfo dir = new DirectoryInfo(@"C:\ProgramData\myFolder");
if ((bool)(dir?.Exists))
{
dir?.Delete(true);
}
}
}
Edit: I tried this code and I'm getting the very same error:
var programFiles = Environment.ExpandEnvironmentVariables("%ProgramFiles%");
var manifestFile = Path.Combine(programFiles,@"\My Company\myFile.man");
FileInfo fInfo = new FileInfo(manifestFile);
if ((bool)(fInfo?.Exists))
{
FileSecurity security = fInfo.GetAccessControl();
security.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null),
FileSystemRights.ReadAndExecute, AccessControlType.Allow));
fInfo.SetAccessControl(security);
}
var CMDCommand = $@"/C wevtutil im {manifestFile}";
Process.Start("CMD.exe", CMDCommand);
I tried also this:
var programFiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
var manifestFile = programFiles + @"\My Company\myFile.man";
Running this code on C:\
is working fine..