当前位置首页 > 百科> 正文

Interop.IWshRuntimeLibrary.dll

2019-11-27 12:14:21 百科

Interop.IWshRuntimeLibrary.dll

微软用来创建捷径的类库,当在项目中添加Com引用"Windows Script Host Object Model "时,此类库就会出现在项目中。

基本介绍

  • 中文名:Interop.IWshRuntimeLibrary.dll
  • 用途:创建捷径
  • 发明人:微软
  • 缺点:Interop.IWshRuntimeLibrary.dll

套用

1.首先要添加引用.
添加引用的方法非常简单,右击你的项目并选择添加引用,
选择 COM 选项卡并选择 Windows Script Host Object Model

2.引用命名空间
using System.Runtime.InteropServices;//互动服务
using IWshRuntimeLibrary;

3.创建捷径(注释中有详细说明)
//实例化WshShell对象
WshShell shell = new WshShell();
//通过该对象的 CreateShortcut 方法来创建 IWshShortcut 接口的实例对象
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(
Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "//ShortCut.lnk");
//设定捷径的目标所在的位置(源程式完整路径)
shortcut.TargetPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
//应用程式的工作目录
//当用户没有指定一个具体的目录时,捷径的目标应用程式将使用该属性所指定的目录来装载或保存档案。
shortcut.WorkingDirectory = System.Environment.CurrentDirectory;
//目标应用程式视窗类型(1.Normal window普通视窗,3.Maximized最大化视窗,7.Minimized最小化)
shortcut.WindowStyle = 1;
//捷径的描述
shortcut.Description = "ChinaDforce YanMang";
//可以自定义捷径图示.(如果不设定,则将默认源档案图示.)
//shortcut.IconLocation = System.Environment.SystemDirectory + "\\" + "shell32.dll, 165";
//设定应用程式的启动参数(如果应用程式支持的话)
//shortcut.Arguments = "/myword /d4s";
//设定快捷键(如果有必要的话.)
//shortcut.Hotkey = "CTRL+ALT+D";
//保存捷径
shortcut.Save();

缺点:


用这种方法写的程式,必须有Interop.IWshRuntimeLibrary.dll跟着,才能正确执行.对于创建"单档案程式"的人来讲,麻烦了吧。
声明:此文信息来源于网络,登载此文只为提供信息参考,并不用于任何商业目的。如有侵权,请及时联系我们:baisebaisebaise@yeah.net