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 MessageBox.Show(ws.Description);

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值