Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to : Making a program start on Windows startup with wix toolset?

I have simple "Hello world" windows forms application (created in VS-2013).
How to making an aplication start on Windows startup, with WIX Toolset ?
Must work in windows7 and windows8.
This is Product.wxs I have currently.

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Product Id="*" Name="Installer" Language="1033" Version="1.0.0.0" Manufacturer="DMC" UpgradeCode="808c333f-09f7-45d5-a5ab-ea104c500f2b">
        <Package Id="*" InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
        <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
        <MediaTemplate />
        <Feature Id="ProductFeature" Title="Installer" Level="1">
            <ComponentGroupRef Id="ProductComponents" />
        </Feature>
    </Product>
    <Fragment>
        <Directory Id="TARGETDIR" Name="SourceDir">
            <Directory Id="ProgramFilesFolder">
                <Directory Id="INSTALLFOLDER" Name="HelloWorld" />
            </Directory>
      <Directory Id="StartupFolder">
      </Directory>
        </Directory>
    </Fragment>
    <Fragment>
        <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
      <Component Guid="{A4744AE7-211C-42A0-887D-1701D242776C}">
        <File Source="$(var.HelloWorld.TargetPath)" KeyPath="yes" />
      </Component>
  </ComponentGroup>
    </Fragment>
</Wix>

EDIT:
Thank for help, but not good enought for me. Where to add this tags? Should I create shortcut, or wix will do that for me ? Do I have to include shortcut to wix, and how? Do I have to include .ico to wix project and how ? I need, step by step explanation to understand this. Whole Product.wxs for Hello World project example would be the best.
Edit 2:
I still don't know how to resolve this with wix. I used different approach :How to run a C# application at Windows startup?

like image 536
Raskolnikov Avatar asked Feb 03 '15 17:02

Raskolnikov


1 Answers

I haven't had the time to test the structure, in my Wix Directory project at home, but from the top of my head the directory structure should look something like this

<Directory Id="TARGETDIR" Name="SourceDir"> 
  <Directory Id="ProgramFilesFolder"> 
    <Directory Id="INSTALLDIR" .. > 
      <Component ... > 
        <File ... > 
          <Shortcut Id=".." Directory="StartupFolder" ...> 
            <Icon ... /> 
          </Shortcut> 
        </File> 
      </Component> 
    </Directory> 

    <!-- ADD THIS --> 
    <Directory Id="StartupFolder" ...> 
      <Directory Id="MyShortcutFolder" ... /> 
    </Directory> 
  </Directory> 
</Directory> 

** UPDATE **

By default, the Fragment containing the Directory structure is right after the product element.

In the Fragment that declares the directory structure required for your installation, you will add the directory reference to the Start Up folder under windows.

After, you must create the component that will instruct it to take a file and create a ShortCut in the directory that you pass as reference (Start Up Folder).

When the installer launches, it will copy the short cut to the file specified in the directory that you referenced.

** FROM YOUR SOURCE **

In the fragment that has your product components add this declaration

<DirectoryRef Id="StartupFolder">
  <Component Id="ApplicationShortCutStartUp" Guid="{BCC2E481-53AF-4690-912D-1051B930B910}">
    <Shortcut Id="AppShortCutStartUp" Name="DMC"
              Description="DMC HELLO"
              Target="[INSTALLDIR][[ NAME OF YOUR EXE]]"
              WorkingDirectory="INSTALLDIR" />


    <RegistryKey Root="HKLM" Key="DMC\HelloWorld" Action="createAndRemoveOnUninstall">
      <RegistryValue Name="ShortCutStartUp" Type="integer" Value="1" KeyPath="yes"  />
    </RegistryKey>        
  </Component>

</DirectoryRef>

In the Feature tag under product add the reference to your new component so now your product declaration will look like this

  <Product Id="*" Name="Installer" Language="1033" Version="1.0.0.0" Manufacturer="DMC" UpgradeCode="808c333f-09f7-45d5-a5ab-ea104c500f2b">
    <Package Id="*" InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
    <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
    <MediaTemplate />
    <Feature Id="ProductFeature" Title="Installer" Level="1">
      <ComponentGroupRef Id="ProductComponents" />
      <ComponentGroupRef Id="ApplicationShortCutStartUp" />
    </Feature>
  </Product>

That will copy a shortcut to your start-up folder for your machine.

ADJUSTMENTS

This:

<ComponentGroupRef Id="ApplicationShortCutStartUp" />

Should Be

<ComponentRef Id="ApplicationShortCutStartUp" />

This:

<!-- ADD THIS --> 
<Directory Id="StartupFolder" ...> 
  <Directory Id="MyShortcutFolder" ... /> 
</Directory> 

Should be:

<Directory Id="StartupFolder" ...> 
</Directory> 

That should fix your two errors

like image 195
CheGueVerra Avatar answered Nov 15 '22 06:11

CheGueVerra