How to add items to the Windows start-menu after the Project constructor?

Dec 21, 2014 at 7:56 PM
Hello - thank you for providing this interesting and quite-useful project!

Question: How can we add a item (namely, just a simple shortcut to our program executable, under our Vendor-name) to the Windows Start-Menu, separately after the call to the Project constructor?

Trying to do it as in the examples, within the Project ctor itself - is way too convoluted for me - I can't get the code to compile with that in, although I've gotten everything else to work.

The infor on the Project ctor itself, is lacking. If I can come to understand that - I'd like to help flesh out the documentation for it, if you like.

Thanks, jh
Dec 30, 2014 at 12:01 PM
Look at the setup in Samples/Release Folder. It does something a bit different but I hope you will get the clue.

The tricks seems to be to use LINQ after the constructor call

project
        .FindFile((f) => f.Name.EndsWith("MyApp.exe"))
        .First()
        .Shortcuts = new[] {
                                new FileShortcut("MyApp.exe", "INSTALLDIR"),
                                new FileShortcut("MyApp.exe", "%Desktop%")
                           };
I personally think that the Start Menu sucks but since it seems to be popular and will be reintroduced in Windows 10...
Jan 2, 2015 at 8:32 AM
Thank you for replying Repete4711.

How would this work? What does this code do?
new fileShortcut("MyApp.exe", "INSTALLDIR")
Is that placing a shortcut to MyApp.exe within the installation directory? Why do that?


and this code:
new FileShortcut("MyApp.exe", "%Desktop%")
Does that place a shortcut to MyApp.exe onto the Windows Desktop? How do you control what the text of the shortcut is? And what informs this statement WHERE that file MyApp.exe is? Does it internally find the file matching that string literal?

Thanks,

jh
Coordinator
Jan 5, 2015 at 2:33 AM
If you want to put the shortcut to the start-menu and desktop then your code (using constructor) will look need to be like this:
 new Dir(@"%ProgramFiles%\My Company\My Product",
         new File(@"AppFiles\MyApp.exe",
                new FileShortcut("MyApp", @"%ProgramMenu%\My Company\My Product"),
                new FileShortcut("MyApp", "%Desktop%")),
         ...
If you want to add shortcuts outside of constructor then you may use initializers:
 new Dir(@"%ProgramFiles%\My Company\My Product",
         new File(@"AppFiles\MyApp.exe")
         {
                Shortcuts = new[]
                            {
                                new FileShortcut("MyApp", @"%ProgramMenu%\My Company\My Product"),
                                new FileShortcut("MyApp", "%Desktop%")
                            }
         }
         ...
If you want to add shortcuts completely outside of your project declaration then you can use LINQ as Repete4711 suggested.

You can find the corresponding sample in the "Wix# Samples\AllInOne" folder.
new FileShortcut("MyApp.exe", "%Desktop%")
Does that place a shortcut to MyApp.exe onto the Windows Desktop?
Yes.
How do you control what the text of the shortcut is?
By default the name of the link (shortcut) file is the name of the executable it is associated with but with the new extension '.lnk'
If you want to have different name then you need to adjust it when the WiX is generated. Thus you need to handle source s you need to handle WixSourceGenerated event:
    static void Compiler_WixSourceGenerated(XDocument document)
    {
        document.Root.Descendants("Shortcut").ToList()
                     .ForEach(x => 
                      {
                          if(x.Attribute("Name").Value == "MyApp.lnk")
                            x.Attribute("Name").Value = "My Product App.lnk";
                      });
    }
And what informs this statement WHERE that file MyApp.exe is? Does it internally find the file matching that string literal?
'FileShortcut' has parent 'new File("AppFiles\MyApp.exe"...,' who is that MyApp.exe.
Jan 6, 2015 at 7:30 AM
That got me going - thank you so very much!!