How to remove a shortcut file in c#

霸气de小男生 提交于 2019-12-11 23:37:27

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!