C# 使用C在Windows 10中查找.lnk快捷方式的目标#
我希望在Windows 10中使用C#查找快捷方式(.lnk文件,而不是符号链接)的目标 我已经搜索了几个小时,找到了很多方法来实现这一点,但我发现了两条值得纪念的评论,即Windows10中的快捷方式有些不同。另一个原因是它比听起来更复杂。我尝试过的方法都不管用。我已经引用了所有必需的COM对象 它们编译(完整的程序编译),但不生成输出,只有Shell32 idea有权限错误 我尝试过的示例(片段) 它们是片段,但传达了输入、过程和结果的思想 我找到的唯一其他线索是一个.lnk文件结构的Microsoft文档。我见过解析它们的解决方案(旧版本),但我真的希望使用现代API 所以我总结了(是的,是拼写)我想要什么,我尝试了什么,以及代码是如何失败的C# 使用C在Windows 10中查找.lnk快捷方式的目标#,c#,icons,shortcut,C#,Icons,Shortcut,我希望在Windows 10中使用C#查找快捷方式(.lnk文件,而不是符号链接)的目标 我已经搜索了几个小时,找到了很多方法来实现这一点,但我发现了两条值得纪念的评论,即Windows10中的快捷方式有些不同。另一个原因是它比听起来更复杂。我尝试过的方法都不管用。我已经引用了所有必需的COM对象 它们编译(完整的程序编译),但不生成输出,只有Shell32 idea有权限错误 我尝试过的示例(片段) 它们是片段,但传达了输入、过程和结果的思想 我找到的唯一其他线索是一个.lnk文件结构的Mic
在透视图中,目标是有一个快捷方式窗口,但我似乎需要返回到可执行文件,以便在列表视图中获得不同大小的图标。您可以尝试以下操作:
public static void CreateShortcut(string shortcutName, string shortcutPath, string targetFileLocation)
{
string shortcutLocation = System.IO.Path.Combine(shortcutPath, shortcutName + ".lnk");
WshShell shell = new WshShell();
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutLocation);
shortcut.Description = "Discription"; // The description of the shortcut
shortcut.IconLocation = "Path";// The icon of the shortcut
shortcut.TargetPath = targetFileLocation; // The path of the file that will launch when the shortcut is run
shortcut.Save(); // Save the shortcut
}
以下是您将如何使用它:
CreateShortcut("Name", PathToDesktop, InstallPathwitheExtention");
答案如下:
如果当前不存在应用程序清单文件,app.Manifest
,请将其添加到解决方案的启动项目中(右键单击project->Add->New Item->General->Application Manifest File)。
在你的app.manifest
文件中
替换这一行代码:
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
为此:
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
requireAdministrator
使您的应用程序以管理员权限运行,并授予您所需的访问权限
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />