2

I want to register my application to start as windows launches based on a check box in the exit dialog.

I followed this but it seem that the writing to the registry is done before the end dialog (and the relevant check box) even appear.

My code is: in 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>

in 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>

EDIT: I tried adding the key to the registry and in case the user un-check the check box delete it using a custom action. my code:

[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>

The result is, during instalation I write the key to the registry, but when I uncheck the check box and press finish, the key in not removed from the registry. Any Ideas why?

Community
  • 1
  • 1
eskadi
  • 245
  • 3
  • 17

2 Answers2

1

The other choice is to write a custom action that runs at the end of the install based on the value of the checkbox, and again you'd need to remove that registry entry at uninstall.

As suggested, it is better to make it a configuration of the app and not the install. If the user changes his mind, what's he supposed to do? Fiddle in the registry (if he can figure out where it is)? Uninstall and re-install to change the setting?

By the way, the program does not start "as windows launches". It will start when the user logs on, and that's not the same thing. If you want it to launch when the user logs on I would describe it to your users as "when you logon". If you want it launch when Windows starts it would need to be a service.

PhilDW
  • 20,260
  • 1
  • 18
  • 28
  • thanks! It is already configurable from the app, but I still want it also from the installer. I edited my question based on your answer, trying to use custom action did not work. – eskadi Mar 17 '14 at 13:42
0

Sounds like you have a conditional feature. Remove the check box and instead make a sub-feature.


Another take...

User choices like that are not an installation issue; They are a configuration issue. There is a fine and wavy line between the two. The application's programs should manage its own configuration.

After the installation is complete and your user has made a configuration choice, your installer can launch a configuration program with command-line arguments to add or modify the Run key.

The installer could remove the registry entry upon uninstallation since it would be better to clean up the Run key than to preserve user's choice for when they install your application again.

Tom Blodget
  • 20,260
  • 3
  • 39
  • 72