I have written a x64 windows installer for a C# windows service. The windows service itself targets Any CPU. It installs the service correctly to "Program Files". However, when uninstalling, I need to remove the logs directory. But when I try to obtain the path to "Program Files" using Environment ,it returns "Program Files (x86)", and hence fails to find the logs directory and delete it.How do I get around this. The code runs in the ProjectInstaller class and is as below
try
{
string path = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + @"\PathToLogsFolder";
logger.Info(path);
//The above line always shows Program Files (x86) instead of "Program Files"
if (Directory.Exists(path))
{
Directory.Delete(path, true);
}
else
{
logger.Info("Path does not exist:"+path);
}
}
catch (Exception e)
{
logger.Error("Failed to delete Logs directory on uninstall:" + e.Message);
logger.Error(e.StackTrace);
}