【问题标题】: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


    【解决方案1】:

    我在这个问题中遇到了这个问题:

    Why does FolderBrowserDialog not allow the desktop as SelectedPath when RootFolder is MyComputer?

    我得到的答案是这样的:

    显然,Win 7 中的桌面实际上并不存在于路径中

    c:\Users\用户名\桌面

    系统在命令提示符和 Windows 中假装它执行 探险家。但是由于它不存在,因此 SelectedPath 的部分 要求其路径位于 RootFolder 下不允许将路径设置为 那样。

    这可能是问题所在。您应该使用 Environment.GetFolderPath 函数来获取真实桌面上的句柄。 :)

    【讨论】:

      【解决方案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"));
          }
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2011-08-03
            • 1970-01-01
            • 2010-11-26
            • 1970-01-01
            • 2011-06-16
            • 1970-01-01
            相关资源
            最近更新 更多