• 如何使用C#操作快捷方式(获取快捷方式属性、创建快捷方式)


    近来项目中有需要用到一个技术:使用C#操控快捷方式,包含创建和读取等。现整理一下实现方式,分享给大家。

    第一步  创建一个项目

    无需废话,跳过。

    第二步  引用COM组件

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

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

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

    第四步  读取快捷方式属性

    获取快捷方式属性
    1 IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShellClass();
    2 IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut("c:\\yeaicc.lnk");
    3 // 亲,根据刚刚创建时的代码,你想获取什么属性?
    4 MessageBox.Show(ws.Description);

    第五步  注意

    转载请注明:本文来自博客园--yeaicc 谢谢。

  • 相关阅读:
    wince开发_摩托罗拉MC3100_打开条码设置
    【Scala类型系统】自身类型(self type)引用
    Scala 基础新手教程
    ActiveMQ消息队列的使用及应用
    nginx配置服务器负载均衡
    ActiveMQ_Linux安装
    js调试工具Console命令详解
    微信JS-SDK选择相册或拍照并上传PHP实现
    微信公众平台开发接口PHP SDK完整版
    微信JS接口汇总及使用详解
  • 原文地址:https://www.cnblogs.com/yeaicc/p/OperateShortcut.html
Copyright © 2020-2023  润新知