Tag: lnk

使用“开始”目录获取Windows .lnk快捷方式的目标

我试图检索Windows .lnk快捷方式的目标路径,但根据.lnk文件的属性,“目标”不是实际的文件路径: 我正在使用IWshRuntimeLibrary,我访问的快捷方式对象是IWshShortcut类型: WshShell shell = new WshShell(); IWshShortcut link = (IWshShortcut)shell.CreateShortcut(lnkFileName); // This returns “C:\Windows\Installer\{F843C6A3-224D-4615-94F8-3C461BD9AEA0}\PaintShopProExeIcon.ico” var targetPath = link.TargetPath; // This is the same as the “Start in” value in the image above var workingDir = link.WorkingDirectory; “link”对象的TargetPath属性不是实际.exe的位置:“C:\ Windows \ Installer {F843C6A3-224D-4615-94F8-3C461BD9AEA0} \ PaintShopProExeIcon.ico” 我可以从这个对象获取WorkingDirectory属性,这似乎与快捷方式的“Start in”属性相同,如上图所示。 我的问题是, 如果TargetPath不是实际的.exe路径 , 如何获得快捷方式打开的.exe文件的实际目标路径 ? 这些信息在哪里? 此示例中的实际目标路径是“C:\ Program […]

创建文件夹名称具有unicode字符的快捷方式

我一直在使用以下代码动态创建快捷方式。 但是当文件夹名称具有像Thai,greek语言这样的unicode字符时,targetPath会抛出Argumentexception。 IWshRuntimeLibrary.WshShell shell = new WshShell(); IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutLocation); shortcut.Description = “My shortcut description”; // The description of the shortcut shortcut.WorkingDirectory = currentPath; shortcut.TargetPath = targetFileLocation; // The path of the file that will launch when the shortcut is run shortcut.Save();

创建文件快捷方式(.lnk)

我一直在寻找一种在C#中创建文件快捷方式的简单方法,但我只找到了那样做的外部dll。 这实际上是相当令人惊讶的,没有内置的方法来做到这一点.. 无论如何,我知道lnk文件只是带有特定命令和给定路径的文本文件。 我想也许我可以创建一个文本文件(在代码中)将它的文本设置为正确的命令并将其扩展名更改为.lnk我尝试先手动执行此操作,但未能这样做。 有没有办法做这样的事情(或者可能是另一种简单的方法)来创建c#中某个路径的快捷方式? 为了清楚起见,通过快捷方式我的意思是一个.lnk文件,它导致文件 编辑:而文件我指的是我想要的任何文件,而不仅仅是我自己的应用程序的快捷方式 如果它不适合每个场景,我会编辑。 添加以下参考: Microsoft Shell控件和自动化 Windows脚本宿主对象模型 添加此命名空间: using Shell32; using IWshRuntimeLibrary; 接下来似乎工作: var wsh = new IWshShell_Class(); IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut( Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + “\\shorcut2.lnk”) as IWshRuntimeLibrary.IWshShortcut; shortcut.TargetPath = @”C:\Users\Zimin\Desktop\test folder”; shortcut.Save(); 希望它能帮助其他人,感谢您的关注。 另外,如果有一种创建文件的方法,请编写正确的命令,然后将其更改为lnk文件,请告诉我。