wix - 获取父目录 [英] wix - getting parent directory
问题描述
我的安装程序需要从注册表中读取一个值并将安装路径设置为该值的父级.
My installer needs to read a value from the registry and set the install path to parent of that value.
例如,我从注册表中得到:
For example, from registry I get:
D:\apps\client
然后安装程序应该将应用安装到
Then the installer should install the app to
D:\apps
我尝试了 [DIR]\..\
(在目录"或CustomAction"中),但在安装时看到以下错误:
I tried [DIR]\..\
(in "Directory" or "CustomAction"), but seeing following error when installing:
Error 1324. The folder path '..' contains an invalid character.
如何使用 WiX 做到这一点?
How can I do this with WiX?
推荐答案
纯 wix 好像不行.您可以使用 自定义操作类型1.在LaunchConditions"操作之前以立即模式执行它.在您的 wix-code 新属性中的某处初始化,例如:
It seems that you can't do it with pure wix. You can use the Custom Action Type 1. Execute it in immediate mode before 'LaunchConditions' action. Initialize somewhere in your wix-code new property like:
<Property Id="DIRFROMREG" Value="0" Secure="yes">
这是关于 C# 的示例:
And here is sample on C#:
public class CustomActions
{
[CustomAction]
public static ActionResult DirectorySearchAction(Session session)
{
try
{
session.Log("Directory search");
RegistryKey reg = Registry.LocalMachine.OpenSubKey(@"...your subkey...");
if (reg != null)
{
var dir=reg.GetValue("...your value...");
/*
var parentdir= split here your directory
*/
session["DIRFROMREG"] =parentdir;
session.Log(@"directory is ");
}
else
{
session.Log(@"The registry key is not found");
}
}
catch (Exception e)
{
session.Log(@"Error "+e);
}
return ActionResult.Success;
}
}
最后一件事:
<SetProperty Id="INSTALLLOCATION" Value="[DIRFROMREG]" After="Your custom action">NOT DIRFROMREG=0</SetProperty>
希望这会有所帮助.
这篇关于wix - 获取父目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!