且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在C#中删除快捷方式文件

更新时间:2023-02-08 08:24:33

要获取开始菜单的位置,请使用

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