您的位置:首页 > 编程语言 > C#

C#创建桌面快捷方式

2015-10-27 19:10 471 查看
1、添加引用Windows Script Host Object Model,并引用命名空间using IWshRuntimeLibrary;



2、代码

using System;
using IWshRuntimeLibrary;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void CreateShortCut()
{
string DesktopPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop);//得到桌面文件夹
WshShell shell = new WshShell();
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(DesktopPath + "\\我的快捷方式.lnk");
shortcut.TargetPath = @"D:\\kankan\\";
shortcut.Arguments = "";// 参数
shortcut.Description = "我用C#创建的快捷方式";
shortcut.WorkingDirectory = @"D:\\kankan";//程序所在文件夹,在快捷方式图标点击右键可以看到此属性
//shortcut.IconLocation = @"D:\software\cmpc\zy.exe,0";//图标
shortcut.Hotkey = "CTRL+SHIFT+Z";//热键
shortcut.WindowStyle = 1;
shortcut.Save();
this.Close();
}
private void button1_Click(object sender, EventArgs e)
{
CreateShortCut();
}
}
}


3、结果及属性查看

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: