Shortcut.Description = "Shortcut for TestApp" IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(appStartMenuPath ".lnk") I'd hate to see you mess up something on your system because of a blind following to code I posted. And especially here where you're playing with things like this, make sure you understand each line before you execute it. But for good measure, I believe this code should work. It's more personal preference than anything, and I'd normally be all for using a pre-established API for this, but when the solution is this simple I'm just not sure how worth it that option really is. I see another answer on that question that lists how to do it with the Windows API and some COM interop, but I'd be tempted to shy away from that and just use the above code if it works. This code is untested, of course, but it was accepted on that other question and it looks right. String icon = pathToExe.Replace('\\', '/') Writer.WriteLine("URL=file:///" pathToExe) using (StreamWriter writer = new StreamWriter(appStartMenuPath ".url")) To copy from that answer, you'll need to create the shortcut file yourself. This is pretty much the same as this question: Create shortcut on desktop C#. Create Shortcut for Application Settings String programs_path = Path.Combine(allUserProfile.ToString(), "Programs") The above API call returns: C:\ProgramData\Microsoft\Windows\Start Menu SHGetSpecialFolderPath(IntPtr.Zero, allUserProfile, CSIDL_COMMON_STARTMENU, false) StringBuilder allUserProfile = new StringBuilder(260) Public static void CreateShortcutForAllUsers() Static extern bool SHGetSpecialFolderPath(IntPtr hwndOwner, StringBuilder lpszPath, int nFolder, bool fCreate) You can get common profile path for All Users by using API function SHGetSpecialFolderPath. Shortcut.Description = "Click to edit SampleApp settings" Shortcut.IconLocation = Files\YourAppFolder\settings.ico" Shortcut.TargetPath = Files\YourAppFolder\MyAppSettings.exe" IWshShortcut shortcut = (IWshShortcut)shellClass.CreateShortcut(settingsLink) String settingsLink = Path.Combine(shortcutFolder, "Settings.lnk") WshShellClass shellClass = new WshShellClass() String shortcutFolder = Path.Combine(programs_path, (!Directory.Exists(shortcutFolder))ĭirectory.CreateDirectory(shortcutFolder) Note: To use Windows Script Host library, you need to add a reference under References > COM tab > Windows Script Host Object Model.Ĭreate shortcut only for Current User: string programs_path = Environment.GetFolderPath() In C#, you can create shortcut using Windows Script Host library. But when it comes to custom installer setup, you need to write custom code to create All Programs shortcut. By MSI setup, you can easily create Start Menu Shortcut for your application.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |