- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我们有用户将他们桌面上的快捷方式文件重命名为我们的应用程序。如果应用程序的图标发生变化,基于目标路径删除/修改快捷方式的最佳方法是什么?换句话说,我很难找到文件名,因为它一直在变化。
最佳答案
这是一个很好的问题,我很惊讶在 10 年内没有人回答正确。
下面的代码遍历给定文件夹中的所有链接,找到一个 TargetPath
指向当前正在执行的 WinForms 应用程序的链接。
将对项目的 COM 引用添加到 Windows 脚本宿主对象模型
。
using IWshRuntimeLibrary;
private static void DeleteShortcuts(string path)
{
// Example for path: Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
foreach (var fileName in Directory.GetFiles(path, "*.lnk"))
{
WshShell shell = new WshShell();
IWshShortcut link = (IWshShortcut)shell.CreateShortcut(fileName);
if (link.TargetPath == Application.ExecutablePath)
{
System.IO.File.Delete(fileName);
}
}
}
注意: Application.ExecutablePath
适用于 WinForms 以获取当前的 exe 路径,对于控制台应用程序,您应该使用 Path.GetDirectoryName(Environment.GetCommandLineArgs() [0])
。请参阅其他类型项目的文档。
关于c# - 使用 C# 通过 targetpath 删除/修改快捷方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11512048/
我似乎无法让 WShell 返回 objShortcut.TargetPath 的值,尽管它可以很好地传递全名。 我一直在阅读 WShell 可能会遇到远程磁盘问题,而我一直在使用外部驱动器。 在我的
我有一个文件 custom.props我在这里定义了一些要在项目中使用的宏。在这个例子中,我有这个: $(TargetPath) /noload /nosave /noexc /noft 当我加载项目
我有使用 Ionic Framework 和 AngularJS 编写的项目。他的任务是从 URL 下载文件,输入 http://www.uzhnu.edu.ua/uk/infocentre/get/
我们有用户将他们桌面上的快捷方式文件重命名为我们的应用程序。如果应用程序的图标发生变化,基于目标路径删除/修改快捷方式的最佳方法是什么?换句话说,我很难找到文件名,因为它一直在变化。 最佳答案 这是一
我已经看到了$this->getTargetPath($request->getSession(), $providerKey)可以用来获取目标路径,但它总是 null . 有人可以解释一下它的用途以
我已经看到了$this->getTargetPath($request->getSession(), $providerKey)可以用来获取目标路径,但它总是 null . 有人可以解释一下它的用途以
我收到许多这样的警告: C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets(1151,5): warning
我是一名优秀的程序员,十分优秀!