1

I have an MSI installer that installs my Windows Service and in my custom actions I need to write some values into the Registry in the HKEY_LOCAL_MACHINE/SOFTWARE/MYSoftware key.

I am trying to do this and it's not working, but from my Windows Service it's working fine. Can anybody tell me where I am going wrong?

string registryLocaltion = AgentProperties.TMAGENT_REGISTRY_LOCATION
                           + @"\" +AgentProperties.TMAgentVersion;

tmKeyMain = Registry.LocalMachine.OpenSubKey(registryLocaltion, true);
if (tmKeyMain == null)
{
    log.Error("Unable to open registry key " + registryLocaltion);
}

tmKeyMain.SetValue("UseProxySettings", settings.UseProxySettings);
if (settings.UseProxySettings)
{
    tmKeyMain.SetValue("ProxyHost", settings.ProxyHost);
    tmKeyMain.SetValue("ProxyPort", settings.ProxyPort);
    tmKeyMain.SetValue("ProxyUsername",
              GenericHelper.ConvertToBase64Encoding(settings.ProxyUsername));
    tmKeyMain.SetValue("ProxyPassword",
              GenericHelper.ConvertToBase64Encoding(settings.ProxyPassword));
    tmKeyMain.SetValue("ProxyExclusion", settings.ProxyExclusion);
    tmKeyMain.SetValue("BypassProxy", settings.BypassProxy);
}

This code is working fine in my Windows Service, but if I do some thing very similar in my custom action in the MSI installer it doesn't work.

Can anybody tell me where I am going wrong?

4

1 回答 1

2

你遇到了几个问题。最明显的问题是 Visual Studio 部署项目错误地安排自定义操作来模拟客户端上下文。这意味着在 UAC 场景中,您将没有权限。快速解决方法是从已经提升的命令提示符上下文中运行 MSI。

第二个问题是 Visual Studio 部署项目过多地抽象/隐藏了底层 MSI。对于自定义操作,它只为您提供“安装、卸载、回滚、提交”选项,而不会公开任何其他设置。它隐藏了 ServiceInstall 和 ServiceControl 表。这会导致您编写一个重新发明轮子的自定义操作。

看,您应该做的所有自定义操作都是执行业务逻辑和设置属性。然后你应该使用注册表来设置基于属性的数据。通过这种方式,您可以尽可能多地利用 Windows Installer 以及所有它的免费事务/回滚功能。

这个问题一遍又一遍地重复,这就是微软在 VS2012 中杀死设置项目类型的原因。

如果是我的安装,我会重构设计以使用 AppSearch/Reglocator 读取数据,使用极简的自定义操作来进行处理,然后使用注册表表来应用数据。

这将要求您至少查看 Windows Installer XML 以创建一个合并模块,该模块具有所有这些逻辑并合并到您现有的安装项目中。不过这需要一段时间来学习。

于 2013-05-14T11:53:45.583 回答