3

I am trying to create a shortcut in the common startup folder so when any user logs on my application is run. I am using the nuget package WinSharp version 1.0.36.2 to create an MSI installer.

Below is my Main from the WinSharp project. The idea is to install the app to program files and create a shortcut in the startup folder (C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp). The commented out line that creates a shortcut on the desktop works fine. Building the current version gives the error:

Error ICE38: Component StartupFolder.EmptyDirectory installs to user profile. It must use a registry key under HKCU as its KeyPath, not a file.

Is there a different directory Id like Desktop that will work for the startup folder?

var project = new ManagedProject("Plate Synthesis Listener Setup",
new Dir(@"%ProgramFiles%\myCompany/myApp",
    new File(@"..\myApp\bin\Debug\myApp.exe")
    {
        //Shortcuts = new[] {new FileShortcut("myApp", "%Desktop%")}
        Shortcuts = new[] {new FileShortcut("myApp", "StartupFolder")}
    },
    new Files(@"..\myApp\bin\Debug\*.dll"),
    new File(@"..\myApp\bin\Debug\myApp.exe.config")
    {
        GUID = new Guid("My new GUID"),
        ManagedUI = ManagedUI.Empty,
        Version = new Version(1, 0, 1)
    };

    project.ManagedUI.InstallDialogs.Add(Dialogs.Welcome)
           .Add(Dialogs.Progress)
           .Add(Dialogs.Exit);

    project.BuildMsi();

Other threads I have seen but are for XML not C#:

Wix create shortcut in user startup folder

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

Community
  • 1
  • 1
Zathos
  • 43
  • 8

4 Answers4

0

You can use %ProgramMenu\Startup% for startup folder location

0
  //This will create three shortcuts         
  project.FindFile(f => f.Name.EndsWith("myapp.exe"))        
            .First()        
            .Shortcuts = new[]{         
                    new FileShortcut("myapp", "INSTALLDIR"),         
                    new FileShortcut("myapp","%Desktop%"),        
                     new FileShortcut("myapp","%Startup%")         
  };      
user1207414
  • 41
  • 1
  • 2
  • 3
0

The accepted answer didn't work for me, it caused the error ICE38: Component installs to user profile.

What worked for me was to use the registry:

 new RegValue(RegistryHive.LocalMachine,
     @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run",
     "MyApplication",
     @"[INSTALLDIR]MyFolder\MyApp.exe"),
Daniel
  • 21,933
  • 14
  • 72
  • 101
0

None of these worked for me, but this did:

        project.ResolveWildCards().FindFile(f => f.Name.EndsWith("My.exe")).First()
            .Shortcuts = new[]{
            new FileShortcut("Shortcut name", @"%AppData%\Microsoft\Windows\Start Menu\Programs")
        };

The key difference is using @"%AppData%\Microsoft\Windows\Start Menu\Programs".

MoonBoots89
  • 355
  • 2
  • 16
  • Doing this in 2 steps fixed my problem. Create the new ManagedProject, then find the exe and add the new FileShortcut. – Zathos Jan 04 '18 at 13:53