[英]When uninstalling a windows service with a x64 installer , Environment.SpecialFolder.ProgramFiles returns “Program Files (x86)”
I have written a x64 windows installer for a C# windows service. 我已经为C#Windows服务编写了x64 Windows安装程序。 The windows service itself targets Any CPU. Windows服务本身针对任何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. 但是,当我尝试使用Environment获取“ Program Files”的路径时,它返回“ Program Files(x86)”,因此无法找到日志目录并将其删除。如何解决此问题。 The code runs in the ProjectInstaller class and is as below 该代码在ProjectInstaller类中运行,如下所示
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);
}
The most likely explanation is that your code is running as 32-bit code, not as native 64-bit code. 最可能的解释是您的代码以32位代码而不是本机64位代码运行。 You have a 64-bit installer but that does not mean that all your code will run 64-bit. 您有一个64位安装程序,但这并不意味着您的所有代码都将运行64位。 You don't explicitly say this, but if that removal code is in a custom action then build that code to be explicitly 64-bit, and the same with the service. 您没有明确地说出来,但是如果该删除代码处于自定义操作中,则将该代码构建为显式64位,并且与服务相同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.