【问题标题】:How to programatically delete shortcut from user's desktop?如何以编程方式从用户桌面删除快捷方式?
【发布时间】:2012-02-29 23:53:27
【问题描述】:
使用 C#,如何从用户桌面删除快捷方式?
试过了,没有成功:
string WinUser = WindowsIdentity.GetCurrent().Name;
WinUser = WinUser.Substring(WinUser.LastIndexOf("\\") + 1);
File.Delete("C:\\Users\\" + WinUser + "\\Desktop\\Touch Data.lnk");
我错过了什么?感谢您对此的任何建议!
【问题讨论】:
标签:
c#
icons
shortcut
delete-file
【解决方案2】:
尝试以下方法:
string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
File.Delete(Path.Combine(desktopPath, "Touch Data.lnk"));
【解决方案3】:
System.IO.File.Delete("C:/Users/Public/Desktop/Game.lnk");
:)) win7 标准用户名 public
【解决方案4】:
我有同样的情况,我必须检查快捷方式是否存在,然后将其删除。我使用了以下代码
string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
if(System.IO.File.Exists(Path.Combine(desktopPath , "shortcut.lnk")))
{
System.IO.File.Delete(Path.Combine(desktopPath , "shortcut.lnk"));
}