Wix:将自定义操作中的文件复制到程序目录(Windows 7)
我创建了一个托管 CustomAction
将 *.MSI 中未包含的 2 个文件复制到安装目录。
虽然这在 Windows XP 中有效,但在 Windows 7 中失败。虽然日志显示文件已复制到所需位置 C:\Program Files\MyApp\
,但它们实际上被复制到 C:\Users\MyUser\AppData\Local\VirtualStore\Program Files (x86)\MyApp\
。 我的猜测是,这与修改程序文件夹的访问权限有关。
这就是我在 WiX 中调用自定义操作的方式:
<CustomAction
Id='InstallSource'
BinaryKey='SrcInstActionDll'
DllEntry='InstallSourceFiles'
Execute='deferred'
Impersonate='no'/>
<CustomAction
Id="InstallSource.SetProperty"
Return="check"
Property="InstallSource"
Value='Files=[SourceDir]$(var.SourceZipName),[SourceDir]$(var.SymbolsZipName);TargetDir=[ParentFolder]'
Execute='immediate'/>
CustomAction
本身只是调用 File.Copy()
。安装程序复制的其他文件在 Windows 7 中完美运行。只有那些使用 CustomAction
复制的文件才会出现所描述的问题。
I created a managed CustomAction
to copy 2 files not included in the *.MSI to the installation directory.
While this works in Windows XP, it fails in Windows 7. Although the log say the files are copied to the desired location, C:\Program Files\MyApp\
, they are actually copied to C:\Users\MyUser\AppData\Local\VirtualStore\Program Files (x86)\MyApp\
.
My guess is that this has to do with access rights to modify the program folder.
This is how I call the custom action in WiX:
<CustomAction
Id='InstallSource'
BinaryKey='SrcInstActionDll'
DllEntry='InstallSourceFiles'
Execute='deferred'
Impersonate='no'/>
<CustomAction
Id="InstallSource.SetProperty"
Return="check"
Property="InstallSource"
Value='Files=[SourceDir]$(var.SourceZipName),[SourceDir]$(var.SymbolsZipName);TargetDir=[ParentFolder]'
Execute='immediate'/>
The CustomAction
itself simply invokes File.Copy()
. Other files copied by the installer work perfectly in Windows 7. Only those files copied using the CustomAction
have the described problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实际上,此行为是由以标准用户身份运行的 32 位应用程序(在 64 位 Windows 中)尝试写入某些特权文件夹时触发的文件系统重定向引起的。
对我来说,您的自定义操作似乎没有提升运行。由于自定义操作定义看起来正确,剩下的问题是您在哪里触发此自定义操作。
既然您提到了日志,我假设您正在运行 msiexec 并检查日志。
确保您的自定义操作在如下所示的行之后运行:
不久前,我在自定义操作和 此博文 帮助我弄清楚如何解决它。这是我认为可能有帮助的另一篇文章
希望这有帮助
Indeed this behavior is caused by the file system redirection triggered when a 32 bit app (in a 64 bits Windows) running as an standard user tries to write to some privileged folder.
For me it looks like your custom action is not running elevated. Since the custom action definition looks correct the question that remains is where you are firing this custom action.
Since you mention the log I assume you are running msiexec and checking the logs.
Make sure that your custom action runs after a line that looks like:
Some time ago I had a similar issue with custom actions and this blog post helped me to figure out how to fix it. This is another post that I think may help
Hope this helps
正如您所说,我认为您的自定义操作需要提升。由于您的 CA 是一个 .Net 项目,因此将其设置为支持提升是很容易的。
请检查下一个链接,它对如何在 .Net 项目上处理 UAC 有很好的解释。
启用您的应用程序-for-uac-on-vista
希望有帮助。
Like you said, I think that your Custom Action needs elevation. Since your CA is a .Net project, it's kind of eassy to set it up to support elevation.
Please check the next link, it has a good explanation on how to handdle UAC on a .Net project.
enabling-your-application-for-uac-on-vista
Hope it helps.