Hi,
How to remove a shortcut file in c#,how to remove the program icon from the Programs folder?.
Redards, Harsh Suman
Hi,
How to remove a shortcut file in c#,how to remove the program icon from the Programs folder?.
Redards, Harsh Suman
You can use the standard file operations on shortcuts.
I believe the file extension is lnk.
A shortcut file is a normal file that happens to redirect (on click) the call to another file, program or directory. To remove a shortcut you can use the File.Delete method.
File.Delete(path_to_lnk_file);
To get the start menu location, use the SpecialFolder enumeration. Something like the following should get you started:
string startMenuDir = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu);
string shortcut = Path.Combine(startMenuDir, @"The Company\MyShortcut.lnk");
if (File.Exists(shortcut))
File.Delete(shortcut);
If you don't know the exact file name, you could enumerate over all the files in the start menu folder using Directory.GetFiles or Directory.GetDirectories. You could also remove the entire folder ("The Company"), using Directory.Delete
In Windows explorer, the file extension for links (lnk) is never shown, even if you have disabled the Hide extensions for known file types feature.
So if you want to delete the 'Shortcut to foobar.exe' shortcut, you have to do
File.Delete("Shortcut to foobar.exe.lnk");