怎样用C#编写创建快捷方式呢?要注释。谢谢!!!!
解决方案 »
- 并行计算如何动态添加任务?
- 求高手解答:C#自定义结构体中有数组,如何使用Socket发送
- Intelligencia.UrlRewriter 多个参数问题
- c# 有关开发环境的问题
- 在windows编程中(指的是应用程序,不是指ASP.NET WEB应用程序),可不可以象ASP.NET WEB应用程序那样有web.config配置文件,若可以又如何配置
- 数据库告急
- SaveFileDialog能不能选择文件夹而不是文件?
- 这么写的好处
- ProgreessBar来显示程序进度
- 请问关于打印的问题
- 【急、救助 200分】关与Pos for .net sdk PosExplorer.GetDevices();找不到打印机的问题
- LINKlable 怎么显示想要打开的网站
using System.Collections.Generic;
using System.Text;
using IWshRuntimeLibrary;
//在引用里面添加“Windows Script Host ObjectModel”
namespace Shortcuts
{
public class Lnk
{
//"FolderPath"快捷方式存放的位置
//"PathLink"指向连接的文件
//"LnkName"快捷方式的文件
//"LnkNote"快捷方式的备注
//"IconLocationPath"指定快捷方式的图标
public void CreateShortcutLnk(string FolderPath, string PathLink,string LnkName, string LnkNote, string IconLocationPath)
{
try
{
WshShell shell = new WshShell();
IWshShortcut Shortcut =(IWshShortcut)shell.CreateShortcut(FolderPath + "\\" + LnkName +".lnk");
Shortcut.TargetPath = PathLink;
Shortcut.WindowStyle = 1;
Shortcut.Description =LnkNote;
Shortcut.IconLocation = IconLocationPath;
Shortcut.Save();
}
catch
{
throw new Exception("出错了");
}
}
}
}
上面的代码就是在C#中创建快捷方式的核心部分。其中这个类需要在引用中添加“WindowsScript Host Object Model”并且USING IWshRuntimeLibrary
下面是一个在VS.NET2005中制作的WINFORM程序。这个程序将演示如何在桌面上创建自己的快捷方式。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace 创建快捷方式
{
publicpartial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Shortcuts.Lnk CreateLnk = new Shortcuts.Lnk();
CreateLnk.CreateShortcutLnk(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory),
Application.ExecutablePath, "我的应用程序", "我的应用程序",Application.ExecutablePath);
MessageBox.Show("成功创建快捷方式");
}
}
}