How to get current user %AppData% folder?

∥☆過路亽.° 提交于 2019-12-25 08:25:22

问题


WIX, MSI-installer.

I build this MSI on some computer where my login name is developer. In my MSI I have such dialog window:

But third variant always contains developer user name even if current user has other login name... How can I fix it?

This is my code of these elements:

<Control Id="rbgrPath" Type ="RadioButtonGroup"
         X="5" Y="80" Width="500" Height="100" Property="INSTALLFOLDER">
  <RadioButtonGroup Property="INSTALLFOLDER">
    <RadioButton
      Text="[$(var.PLATFORMPROGRAMFILESFOLDER)]Autodesk\ApplicationPlugins\ProxyTools.bundle\"
      Value="[$(var.PLATFORMPROGRAMFILESFOLDER)]Autodesk\ApplicationPlugins\ProxyTools.bundle\"
      Height="13" Width="500" X="5" Y="5"/>
    <RadioButton
      Text="$(env.ProgramData)\Autodesk\ApplicationPlugins\ProxyTools.bundle\"
      Value="$(env.ProgramData)\Autodesk\ApplicationPlugins\ProxyTools.bundle\"
      Height="13" Width="500" X="5" Y="20"/>
    <RadioButton
      Text="$(env.AppData)\Autodesk\ApplicationPlugins\ProxyTools.bundle\"
      Value="$(env.AppData)\Autodesk\ApplicationPlugins\ProxyTools.bundle\"
      Height="13" Width="500" X="5" Y="35"/>
  </RadioButtonGroup>
</Control>

UPD

This is of the PLATFORMPROGRAMFILESFOLDER variable definition:


回答1:


This is because $(env.AppData) and other preprocessor strings are evaluated when you build your package. The second radio button's value will also be incorrect on a machine that happens to use a system drive other than C: (or on older—hopefully unsupported—systems that don't use C:\ProgramData). So you should instead use run-time property substitutions:

  • $(env.ProgramData) should be replaced with [CommonAppDataFolder]
  • $(env.AppData) should be replaced with either [AppDataFolder] or [LocalAppDataFolder]
  • If [$(var.PLATFORMPROGRAMFILESFOLDER)] doesn't resolve to [ProgramFilesFolder] or [ProgramFiles64Folder], it should probably be changed to do so.

Note that it's fine to use additional directory properties to refer to these locations, as long as you are setting their values from the properties referenced above.



来源:https://stackoverflow.com/questions/39995743/how-to-get-current-user-appdata-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!