【问题标题】:Cannot create/write to files/folders after running a Wix Installer for my application, even after deleting folder为我的应用程序运行 Wix 安装程序后,即使在删除文件夹后也无法创建/写入文件/文件夹
【发布时间】:2020-03-30 10:33:57
【问题描述】:

在我用于安装程序的 Product.wxs 文件中,我有一个功能可以在 ProgramData 中创建一些文件夹并向其中添加一些文件

<Feature Id="IOFilesFeature" Title="Settings and IO Files" Level="1">
      <Feature Id="Languages" Title="Languages" Level="2">
        <Feature Id="Languages_UK" Title="English" Level="3">
          <ComponentGroupRef Id="ProgramData_MFR_PRD_Languages_UK" />
        </Feature>
      </Feature>
      <Feature Id="OpsPC1" Title="Operator PC 1" Level="2">
        <Feature Id="OpsPC1_Settings" Title="Settings" Level="3">
          <ComponentGroupRef Id="ProgramData_MFR_PRD_Settings_Ops1" />
        </Feature>
        <Feature Id="OpsPC1_IO" Title="IO" Level="1">
          <ComponentGroupRef Id="ProgramData_MFR_PRD_IO_Ops1" />
        </Feature>
      </Feature>
</Feature>
<Fragment>
      <Directory Id="CommonAppDataFolder" Name="ProgramData">                                   
        <Directory Id="PD_MFR" Name="CompanyName">                                                  
          <Directory Id="PD_MFR_PRD" Name="ProductName">                                            
            <Directory Id="PD_MFR_PRD_Languages" Name="Languages" />                        
            <Directory Id="PD_MFR_PRD_Settings" Name="Settings" />             
            <Directory Id="PD_MFR_PRD_IO" Name="IO" />               
          </Directory>
        </Directory>
      </Directory> 
</Fragment>

每个文件都类似这样:

<Fragment>
    <ComponentGroup Id="ProgramData_MFR_PRD_IO_Ops1" Directory="PD_MFR_PRD_IO">
      <Component Id="FileID" Guid="2be6ba39-9496-4985-8317-5bd0b3f88f95">
        <File Id="FileID" Name="FileName" Source="SourceLocation" />
      </Component>
    </ComponentGroup>
  </Fragment>

我在使用安装程序后注意到程序无法编辑文件。手动编辑将仅显示在 Windows 资源管理器中。当我从下面的代码中读取文件内容后查看文件内容时,内容不会更新为我手动更改的内容。

    public static string ReadFile(string fullPath)
    {
      string rv = "";
      try
      {
        if (File.Exists(fullPath))
        {
          FileStream fs = new FileStream(fullPath, FileMode.Open, FileAccess.Read);
          if (fs.CanRead)
            using (StreamReader sr = new StreamReader(fs))
              rv = sr.ReadToEnd();
        }
      }
      catch (Exception ex)
      {
        ex.WriteToFile();
      }
      return rv;
    } 

我从 ProgramData 中删除了 CompanyName 文件夹,以查看它是否允许程序重新创建文件并且程序仍然可以读取该文件。 Windows 资源管理器会显示该文件夹不存在。

您知道是什么导致文件以这种方式“重影”吗?

【问题讨论】:

  • 我在文件夹中搜索了一个特定文件,发现这些文件已在 C:\Users\EdwardMo\AppData\Local\VirtualStore\ProgramData\ 而不是 C:\ProgramData 中重新创建。自从我第一次制作此安装程序以来,我的笔记本电脑已升级到 Windows 10,我认为在那之前不会发生这种情况。这些文件需要在 PC 上的用户之间共享,有没有办法让安装程序使用 C:\ProgramData 而不是虚拟商店?

标签: c# wix3.7


【解决方案1】:

当我发现它正在写入虚拟商店时,我发现了这个:

Privileges/owner issue when writing in C:\ProgramData\

这说安装程序必须给子目录一个许可的ACL。

我跟随Wix: How to set permissions for folder and all sub folders 应用了这个,现在应用程序再次按预期工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-14
    相关资源
    最近更新 更多