WiX:有条件地注册应用程序以在Windows启动时启动

时间:2014-03-12 18:30:33

标签: wix windows-installer wix3.7

我想根据退出对话框中的复选框注册我的应用程序以启动Windows启动。

我跟着this但似乎在结束对话框(以及相关的复选框)之前写入了注册表。

我的代码是: 在product.wxs:

<Property Id="APP_AUTOMATIC_START_UP">1</Property>
....
<Component Id="AppAutoStartUp" Guid="{MyGuid}">
<RegistryValue Id="App.rst" Root="HKCU" Action="write" Key="Software\Microsoft\Windows\CurrentVersion\Run" Name="App" Value="[#MyApp.exe]" Type="string" />
<Condition><![CDATA[Installed OR APP_AUTOMATIC_START_UP]]></Condition>
在MyExitDialog.wxs中:

<Control Id="AutomaticStartup" Type="CheckBox" Height="18" Width="295" X="135" Y="190" Text="Run App upon windows startUp" Property="APP_AUTOMATIC_START_UP" CheckBoxValue="1">
<Condition Action="hide" >Installed</Condition>
<Condition Action="show" >NOT Installed</Condition>

修改 我尝试将密钥添加到注册表中,如果用户取消选中复选框,则使用自定义操作将其删除。我的代码:

[CustomAction]
public static ActionResult NotRunOnStartUp(Session session)
{
    session.Log("Begin NotRunOnStartUp");
    RegistryKey rk = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
    rk.DeleteValue("MyApp"); 
    return ActionResult.Success;
}

<Binary Id="NotRunOnStartUpBinary" src="..\CustomActions\NotRunOnStartUp\bin\$(var.Configuration)\NotRunOnStartUp.CA.dll" />
 ...
<CustomAction Id="NotRunOnStartUpCA"
        Return="check"
        Execute="immediate"
        BinaryKey="NotRunOnStartUpBinary"
        DllEntry="NotRunOnStartUp" />
 ...   
<Publish Dialog="MyExitDialog" Control="Finish" Event="DoAction" Value="NotRunOnStartUpCA">APP_AUTOMATIC_START_UP= 0 and NOT Installed</Publish>

结果是,在安装期间我将密钥写入注册表,但是当我取消选中复选框并按完成时,密钥未从注册表中删除。 任何想法为什么?

2 个答案:

答案 0 :(得分:1)

另一种选择是根据复选框的值编写在安装结束时运行的自定义操作,并且您还需要在卸载时删除该注册表项。

根据建议,最好将其配置为应用程序而不是安装。如果用户改变主意,他应该做什么?在注册表中小提琴(如果他能弄清楚它在哪里)?卸载并重新安装以更改设置?

顺便说一下,当Windows启动时,程序无法启动&#34;。它将在用户登录时启动,这不是一回事。如果您希望在用户登录时启动它,我会将其描述为您的用户&#34;当您登录时#34;。如果您希望在Windows启动时启动它,则需要提供服务。

答案 1 :(得分:0)

听起来你有条件功能。删除复选框,而不是创建子功能。


另一种看法......

这样的用户选择不是安装问题;它们是配置问题。两者之间有一条细线和波浪线。应用程序的程序应该管理自己的配置。

安装完成后,您的用户已选择配置,安装程序可以使用命令行参数启动配置程序以添加或修改Run键。

安装程序可以在卸载时删除注册表项,因为清理Run键比保留用户再次安装应用程序时的选择更好。