This is almost the same as this question: Create a shortcut on the C # desktop .
To copy this answer , you need to create a shortcut file yourself.
using (StreamWriter writer = new StreamWriter(appStartMenuPath + ".url")) { writer.WriteLine("[InternetShortcut]"); writer.WriteLine("URL=file:///" + pathToExe); writer.WriteLine("IconIndex=0"); string icon = pathToExe.Replace('\\', '/'); writer.WriteLine("IconFile=" + icon); }
This code has not been verified, of course, but it has been adopted on this other issue and looks correct.
I see another answer on this question that lists how to do this using the Windows API and some COM interaction, but I will be tempted to avoid this and just use the code above if it works. This is a more personal preference than anything, and I usually had to use a pre-installed API for this, but when the solution is so simple, I'm just not sure how much it really costs. But for a good measure, I believe this code should work. Again, of course, this is completely untested. And especially here, where you play with such things, make sure you understand each line before you execute it. I would really like you to ruin something in your system due to blindly following the code that I posted.
WshShell shell = new WshShell(); IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(appStartMenuPath + ".lnk"); shortcut.Description = "Shortcut for TestApp"; shortcut.TargetPath = pathToExe; shortcut.Save();
You will of course also need a link to the Windows Object Model Windows Script, which can be found in the Add Link section, then COM.
Matthew Haugen
source share