5

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?

Community
  • 1
  • 1
Raskolnikov
  • 3,791
  • 9
  • 43
  • 88

3 Answers3

11

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

CheGueVerra
  • 7,849
  • 4
  • 37
  • 49
  • Thank, but not good enought for me. Where to add this tags? Should I create shorcut, 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 and how ? I need, step by step explanation to understand this. – Raskolnikov Feb 04 '15 at 15:58
  • 2
    You can get my Product.wxs here http://s000.tinyupload.com/?file_id=95468873217085583093 – Raskolnikov Feb 06 '15 at 11:18
  • I have 2 errors: Unresolved reference to symbol 'Directory:StartupFolder' in section 'Fragment:' AND Unresolved reference to symbol 'WixComponentGroup:ApplicationShortCutStartUp' in section 'Product:*'. – Raskolnikov Feb 06 '15 at 11:19
  • 1
    You can get my adjusted version of Product.wxs here http://s000.tinyupload.com/?file_id=70821424679111671809 – CheGueVerra Feb 06 '15 at 17:34
  • Unfortunately I cannot test this till Monday, but I let you know. – Raskolnikov Feb 06 '15 at 22:44
  • It's fine, don't worry about it, but it was a very good idea to use tinyupload, after your next test, add the errors in the comments and the link to your file. – CheGueVerra Feb 06 '15 at 22:54
  • With your Product.wxs I have 4 new errors : 1- Component 'ApplicationShortCutStartUp' has both per-user and per-machine data with a per-machine KeyPath. 2-Component ApplicationShortCutStartUp has non-advertised shortcuts. It's KeyPath registry key should fall under HKCU. 3- Component ApplicationShortCutStartUp installs to user profile. It's KeyPath registry key must fall under HKCU.) 4- Bad shortcut target; Table: Shortcut, Column: Target, Key(s): AppShortCutStartUp.) – Raskolnikov Feb 09 '15 at 07:44
  • Can you reUpload your product.wxs on tinyupload, I will have a look at it later on ... – CheGueVerra Feb 09 '15 at 18:12
  • I just used version that you uploaded, without any changes. – Raskolnikov Feb 09 '15 at 18:52
  • I dont know how to resolve this with wix. I used different approach :http://stackoverflow.com/questions/5089601/run-the-application-at-windows-startup – Raskolnikov Feb 10 '15 at 22:55
  • But you spend lot of time trying to help me, and I am grateful. – Raskolnikov Feb 10 '15 at 22:57
  • Thanks, I didn't have much time this week to help sry – CheGueVerra Feb 11 '15 at 04:22
3

You can only run a program when Windows starts by making it a service or maybe a Task Schedule task that starts it when Windows starts. However nobody is logged on at that point (and maybe will not log on for some time) so you cannot run apps requiring use of the desktop. If you really mean "when a user logs on" then there are at least a couple of choices:

  1. Add a shortcut to the app in the Program Menu Startup folder.

  2. Add the path to the app in the registry Run key. https://msdn.microsoft.com/en-us/library/windows/desktop/aa376977(v=vs.85).aspx

PhilDW
  • 20,260
  • 1
  • 18
  • 28
3

I created registry entry.

<FeatureId="ProductFeature"Title="MyApp"Level="1">
    <ComponentRefId="RegistryEntries"/>
</Feature>

<Fragment>
    <DirectoryRef Id="ApplicationProgramsFolder">

      <Component Id="RegistryEntries" Guid="PUT-GUID-HERE">
        <RegistryKey Root="HKCU"
                     Key="Software\Microsoft\Windows\CurrentVersion\Run"
              Action="createAndRemoveOnUninstall">
          <RegistryValue Type="string" Name="MyApp" Value="&quot;[#MyApp.exe]&quot;" KeyPath="yes"/>          
        </RegistryKey>
      </Component>
    </DirectoryRef>
  </Fragment>

Edit

The value should be escaped so that any spaces in the path don't affect the running of the exe.

Chris Watts
  • 822
  • 1
  • 9
  • 27
Gopala
  • 31
  • 2