如何编辑Windows链接文件中的路径



我想编辑链接文件中的路径,该链接文件指向经常更改路径的文件或文件夹。我在C或其他语言中找到了一些东西,但从来没有在C#中找到过。

Test.lnk->C:TestFolder 1.2.3
我想使用C#将该链接更改为
测试.lnk->C:TestFolder 1.2.4

有人知道怎么做吗?

我认为不可能编辑链接文件中的路径。相反,您可以删除旧的快捷方式,并使用COM Windows脚本主机对象模型创建新的快捷方式:

using System;
using IWshRuntimeLibrary;
namespace ShortCutTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var wsh = new WshShell();
            var shortcut = (IWshShortcut)wsh.CreateShortcut(@"C:cmd.lnk");
            shortcut.Description = "Shortcut for cmd.exe";
            shortcut.TargetPath = Environment.GetFolderPath(Environment.SpecialFolder.System) +  @"cmd.exe";
            shortcut.Save();
        }
    }
}

据我所知,在.NET中没有原生的方法可以做到这一点。

最新更新