0

I'm trying to create an installer that makes the program run on startup for the current user. I can create a shortcut, but I can't seem to put in the right folder.

<!-- some wix stuff -->
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
<!-- more wix stuff -->
<Directory Id="TARGETDIR" Name="SourceDir">
    <!-- more directory stuff -->
    <Directory Id="UserStartupFolder"/>
</Directory>
<SetDirectory Id="UserStartupFolder" Value="[%APPDATA]\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\"/>
<!-- more wix stuff -->
<DirectoryRef Id="UserStartupFolder">
    <Component Id="StartupFolderShortcut" Guid="MyGUID">
        <Shortcut Id="StartupFolderShortcut" Name="MyShortcut" Description="$(var.description)" Target="[#MainExecutable]" WorkingDirectory="INSTALLFOLDER"/>
        <RegistryValue Root="HKCU" Key="Software\$(var.companyDisplayName)\$(var.projectDisplayName)\UserStartupItem" Name="installed" Type="integer" Value="1" KeyPath="yes"/>
    </Component>
</DirectoryRef>
<!-- more wix stuff -->

I don't understand why this doesn't work. If I change the Value of SetDirectory to "[%APPDATA]\\Microsoft\\Windows\\", the shortcut is in that Windows folder as expected, but if I change it to "[%APPDATA]\\Microsoft\\Windows\\Start Menu\\", the shortcut isn't in that Start Menu folder. I don't know if Wix tries to do something special with the Start Menu folder or if there is an issue with the space in the folder name or if it's something else.

The documentation mentions that Value uses the Formatted syntax, but it doesn't mention anything about spaces being an issue. Also, most of the recognized environment variables don't seem to work with this (at least I haven't figured it out), but if those worked, I wouldn't have to hard-code half the path.

How do I create the shortcut in the user's startup folder?

DeadEli
  • 983
  • 2
  • 13
  • 28

1 Answers1

0

Why not using directly the StartupFolder-property? This way you won't have to fiddle with all the odds of creating paths manually.

Regarding your question of why this doesn't work: I don't have a concrete answer, but you could check:

  • What the logfile of an installation reports
  • If the component is installed in both cases correctly.
taffit
  • 1,979
  • 22
  • 23
  • That's what I wanted to do, and I tried `StartupFolder`, but it refers to the all users startup folder, which is not what I want. – DeadEli May 10 '16 at 05:58
  • Then you probably have the [`ALLUSERS`-property](https://msdn.microsoft.com/en-us/library/windows/desktop/aa367559(v=vs.85).aspx) set as stated in the linked description. What you could also try: on the `SetDirectory`-element add the attribute `Sequence="ui"`. The default is `"both"` which should try to set it also in the `ExecuteSequence` which, afaik, runs in the machine context. Any enlightments from the log file? Edit: Maybe also setting explicitely the `Directory`-attribute of the `Shortcut`-element? – taffit May 10 '16 at 08:51
  • Another possibility: using the `WIX_DIR_ALTSTARTUP`-property available from the [Wix' `OSInfo` custom actions](http://wixtoolset.org/documentation/manual/v3/customactions/osinfo.html). For me it seems that it tries to create the shortcut in the machine context and therefore in the `AllUsers`-directories, where some directories aren't available. – taffit May 10 '16 at 09:20
  • And, just to add for other users: it may be that the directory structure has not been built completely in the `Directory`-table. Having the structure defined should ensure that the directory exists and therefore also create the shortcut in the needed folder. – taffit May 11 '16 at 08:56
  • The reason why it is putting the shortcut in the all user's directory and not the current user's directory is because of your InstallScope="perMachine". Change it to InstallScope="perUser". – Garet Jax Jul 10 '18 at 13:33