如何在C#中删除快捷方式文件
问题描述:
如何从程序"文件夹中删除程序图标?
How to remove the program icon from the Programs folder?
答
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);
如果您不知道确切的文件名,则可以使用 Directory.GetDirectories .您还可以使用 Directory.Delete
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