C#创建桌面快捷方式

来源:互联网 发布:淘宝店招牌 编辑:程序博客网 时间:2024/04/29 18:12

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、结果及属性查看


0 0
原创粉丝点击