Create shortcut

Pavle

Well-known member
Joined
Oct 4, 2016
Messages
47
Programming Experience
1-3
I am trying to make app that creates shortcut for selected program.When program starts it show all programs in listbox and you can search for program.How to sort list alphabetically and how to create shortcut from selected program inside listbox and name it like selected program.
 
If your ListBox just contains strings then you can set the Sorted property to true to automatically sort alphabetically.

As for creating a Windows shortcut, there's no dedicated managed API for that. You can find some options here.
 
private void CreateShortcut()
{
object shDesktop = (object)"Desktop";
WshShell shell = new WshShell();
//string shortcutAddress = (string)shell.SpecialFolders.Item(ref shDesktop) + @"\Notepad.lnk";
string shortcutAddress = (string)shell.SpecialFolders.Item(ref shDesktop) + @"\Notepad.lnk";
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutAddress);
shortcut.Description = "New shortcut for a Notepad";
shortcut.Hotkey = "Ctrl+Shift+N";
shortcut.TargetPath = Environment.GetFolderPath(Environment.SpecialFolder.System) + @"\notepad.exe";
shortcut.Save();
}

This function creates notepad shortcut!!!!I want to create shortcut from selected item from listbox!How to do that?
 
Back
Top Bottom