How to create desktop shortcut in C#

private void CreateShortcut()
        {
            try
            {
                WshShellClass wshShell = new WshShellClass();
                IWshRuntimeLibrary.IWshShortcut shortcut;
                string startUpFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
                // Create the shortcut
                if (!System.IO.File.Exists(startUpFolderPath + "\\" + Application.ProductName + ".lnk"))
                {
                    shortcut = (IWshRuntimeLibrary.IWshShortcut)wshShell.CreateShortcut(startUpFolderPath + "\\" + Application.ProductName + ".lnk");
                    shortcut.TargetPath = Application.ExecutablePath;
                    shortcut.WorkingDirectory = Application.StartupPath;
                    shortcut.Description = "File Downloader";
                    shortcut.Save();
                }
            }
            catch (Exception ex) { }
        }




Post a Comment

0 Comments