Wix create shortcut in user startup folder

僤鯓⒐⒋嵵緔 提交于 2019-12-12 01:07:47

问题


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?


回答1:


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.


来源:https://stackoverflow.com/questions/37034783/wix-create-shortcut-in-user-startup-folder

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!