问题
How to remove the program icon from the Programs folder?
回答1:
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
回答2:
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);
回答3:
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");
回答4:
You can use the standard file operations on shortcuts.
I believe the file extension is lnk.
来源:https://stackoverflow.com/questions/211629/how-to-remove-a-shortcut-file-in-c-sharp