简体   繁体   English

无法在MSI安装程序的自定义操作中编写注册表

[英]Unable to write registry in custom action of MSI installer

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. 我有一个MSI安装程序,用于安装Windows Service,并且在我的自定义操作中,我需要在HKEY_LOCAL_MACHINE/SOFTWARE/MYSoftware项中向注册表中写入一些值。

I am trying to do this and it's not working, but from my Windows Service it's working fine. 我正在尝试执行此操作,但它不起作用,但是从我的Windows Service中可以正常工作。 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. 该代码在Windows服务中可以正常工作,但是如果我在MSI安装程序中的自定义操作中执行了一些非常相似的操作,则该代码将无效。

Can anybody tell me where I am going wrong? 谁能告诉我我要去哪里错了?

You are up against a couple problems. 您遇到了几个问题。 The most obvious problem is that Visual Studio Deployment projects incorrectly schedule custom actions to impersonate the client context. 最明显的问题是Visual Studio部署项目错误地安排了自定义操作来模拟客户端上下文。 This means in a UAC scenario you won't have permissions. 这意味着在UAC方案中,您将没有权限。 The quick work around is to run the MSI from an already elevated command prompt context. 快速解决方法是从已经提升的命令提示符上下文中运行MSI。

The second problem is that Visual Studio Deployment Projects abstract / hide the underlying MSI too much. 第二个问题是Visual Studio部署项目过多地抽象/隐藏了底层MSI。 For Custom Actions, it only gives you the options of "install, uninstall, rollback, commit" without exposing any additional settings. 对于“自定义操作”,它仅提供“安装,卸载,回滚,提交”选项,而没有公开任何其他设置。 It hides the ServiceInstall and ServiceControl tables. 它隐藏了ServiceInstall和ServiceControl表。 This causes you to write a custom action that reinvents the wheel. 这会使您编写自定义动作,从而重新构造了轮子。

See, all your custom action should be doing is performing the business logic and setting properties. 看,您所有的自定义操作应该执行的是执行业务逻辑和设置属性。 Then you should be using the Registry table to set the data based on the properties. 然后,您应该使用注册表表根据属性设置数据。 This way you leverage as much of Windows Installer as possible and all of it's free transactional / rollback capabilities. 这样,您可以尽可能多地利用Windows Installer及其所有免费的事务处理/回滚功能。

This problem repeats over and over and is why Microsoft killed of the setup project types in VS2012. 这个问题一遍又一遍地重复,这就是为什么Microsoft在VS2012中取消了安装项目类型的原因。

If it was my install, I'd be refactoring the design to use AppSearch/Reglocator to read in the data, have a minimalist custom action to do the processing and then use the Registry table to apply the data. 如果是我的安装,我将重构设计,以使用AppSearch / Reglocator读取数据,执行极简主义的自定义操作来进行处理,然后使用注册表表来应用数据。

That will require you at a minimum to look at Windows Installer XML to create a merge module that has all of this logic and gets merged into your existing setup project. 这至少需要您查看Windows Installer XML来创建具有所有这些逻辑并被合并到现有安装项目中的合并模块。 That takes awhile to learn though. 不过,这需要一段时间才能学会。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MSI自定义操作安装程序状态交互 - MSI custom action installer state interaction 在安装程序项目中的安装之前添加安装MSI的自定义操作 - Add custom action of installing msi before the setup in installer project 如何将当前的 installer.msi 名称传递给自定义操作? - How to pass current installer.msi name to custom action? 使用带参数的自定义操作时,MSI安装程序无法找到InstallState - MSI Installer cannot find InstallState when using custom action with parameters 无法将我的WiX自定义操作安排到MSI中 - Unable to schedule my WiX Custom Action into the msi 将MSI属性写入通过WiX自定义操作创建的注册表 - Writing MSI property to registry created through WiX custom action Wix 安装程序自定义操作适用于 msiexec /i MyProgramm.msi /l*v thelog.txt 但不适用于正常的 msi 执行 - Wix installer custom action works with msiexec /i MyProgramm.msi /l*v thelog.txt but not with normal msi execution 安装程序自定义操作问题 - 无法写入注册密钥 - Installer Custom Action problem - can't write to register key 如何在 Visual Studio 2010 中为 c# 安装程序编写自定义操作? - how to write custom action for a c# installer in visual studio 2010? 安装程序自定义操作不起作用 - Installer Custom action not working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM