根据快捷方式获取应用程序的图标(去掉快捷方式的箭头)

41 篇文章 0 订阅

第一步  引用COM组件

右键“引用”,“添加引用”,选择“COM组件”,找到“Windows Script Host Object Model”,然后确定。

第二步  编写创建快捷方式的代码

 // 声明操作对象
  IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();
  // 创建一个快捷方式
  IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut("c:\\yeaicc.lnk");
  // 关联的程序
  shortcut.TargetPath = "notepad.exe";
  // 参数
  shortcut.Arguments = "c:\\yeaicc.txt";
  // 快捷方式描述,鼠标放到快捷方式上会显示出来哦
  shortcut.Description = "我的快捷方式--yeaicc";
  // 全局热键
  shortcut.Hotkey = "CTRL+SHIFT+N";
  // 设置快捷方式的图标,这里是取程序图标,如果希望指定一个ico文件,那么请写路径。
  shortcut.IconLocation = "notepad.exe, 0";
  // 保存,创建就成功了。
  shortcut.Save();


第三步  读取快捷方式属性

/// <summary>
/// 获取快捷方式启动路径
/// </summary>
/// <param name="lnkPath">快捷方式路径</param>
/// <returns>启动路径</returns>
private string GetFilePath(string lnkPath)
{
     IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();
     IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(lnkPath);
     //这里可以获取各种属性
     return shortcut.TargetPath;
}
//调用以前写的读取文件的图标,这样获取的图标就是获取启动路径的图标
FileIcon.GetFileIcon(GetFilePath(fileName)

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值