2012-02-14 89 views
0

我想编辑链接文件中的路径,该链接文件使用的文件或文件夹经常更改路径。我在C或其他语言中找到了一些东西,但从未用于C#。如何在Windows链接文件中编辑路径

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

有谁知道怎么做?

+0

查看以下问题的最佳答案: http://stackoverflow.com/questions/234231/creating-application-shortcut-in-a-directory。 – Jalayn 2012-02-14 10:53:44

+0

有没有本地的东西?此外,我还需要一些在WinXP上工作的东西。他们只尝试了Win Server 2008或更高版本。 – theknut 2012-02-14 11:02:55

回答

1

我不认为有可能在链接文件中编辑路径。相反,你可以删除旧的快捷方式,并创建一个使用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中没有原生的方式来做到这一点。