简体   繁体   English

使用x64安装程序卸载Windows服务时,Environment.SpecialFolder.ProgramFiles返回“程序文件(x86)”

[英]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.

相关问题 返回x86的Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) - Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) returning x86 Environment.SpecialFolder.ProgramFiles返回错误的目录 - Environment.SpecialFolder.ProgramFiles returns the wrong directory 作为Windows服务安装时,我的x86 Exe作为x64运行 - My x86 Exe runs as x64 when installed as a Windows Service Windows 7上的32位应用程序的Environment.SpecialFolder.ProgramFiles值? - Environment.SpecialFolder.ProgramFiles value for a 32-bit application on Windows 7? 创建具有 x64 和 x86 依赖项的安装程序 - Create installer with dependencies for x64 and x86 在 Windows 安装程序 (VS2008) 中同时定位 x86 和 x64 - Target both x86 and x64 in the Windows Installer (VS2008) %ProgramFiles(x86)%在64位计算机上的路径(用于注册表) - Path of %ProgramFiles(x86)% in 64 bit machine (for Registry) 相对于x86,在x64下启动Winforms程序10倍 - Startup of Winforms program 10x slower under x64 relative to x86 如何在Environment.SpecialFolder.ProgramFiles C#中转义空间 - how to escape the space in Environment.SpecialFolder.ProgramFiles C# Registry.GetValue()在x86配置中返回null,在x64中工作 - Registry.GetValue() returns null in x86 configuration, works in x64
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM