• 【转】在C#2005中创建快捷方式


    转自:  http://www.cnblogs.com/cfanwolf/

    1using System;
     2using System.Collections.Generic;
     3using System.Text;
     4using IWshRuntimeLibrary;
     5//在引用里面添加“Windows Script Host Object Model”
     6namespace Shortcuts
     7{
     8    public class Lnk
     9    {
    10        //"FolderPath"快捷方式存放的位置
    11        //"PathLink"指向连接的文件
    12        //"LnkName"快捷方式的文件
    13        //"LnkNote"快捷方式的备注
    14        //"IconLocationPath"指定快捷方式的图标
    15        public void CreateShortcutLnk(string FolderPath, string PathLink, string LnkName, string LnkNote, string IconLocationPath)
    16        {
    17            try
    18            {
    19                WshShell shell = new WshShell();
    20                IWshShortcut Shortcut = (IWshShortcut)shell.CreateShortcut(FolderPath + "\\" + LnkName + ".lnk");
    21                Shortcut.TargetPath = PathLink;
    22                Shortcut.WindowStyle = 1;
    23                Shortcut.Description = LnkNote;  
    24                Shortcut.IconLocation = IconLocationPath;
    25                Shortcut.Save();
    26            }

    27            catch
    28            {
    29                throw new Exception("出错了");
    30            }

    31        }

    32    }

    33}

    34

    上面的代码就是在C#中创建快捷方式的核心部分。其中这个类需要在引用中添加“Windows Script Host Object Model”并且USING IWshRuntimeLibrary
    下面是一个在VS.NET2005中制作的WINFORM程序。这个程序将演示如何在桌面上创建自己的快捷方式。
     1using System;
     2using System.Collections.Generic;
     3using System.ComponentModel;
     4using System.Data;
     5using System.Drawing;
     6using System.Text;
     7using System.Windows.Forms;
     8
     9namespace 创建快捷方式
    10{
    11    public partial class Form1 : Form
    12    {
    13        public Form1()
    14        {
    15            InitializeComponent();
    16        }

    17
    18        private void button1_Click(object sender, EventArgs e)
    19        {
    20            Shortcuts.Lnk CreateLnk = new Shortcuts.Lnk();
    21            CreateLnk.CreateShortcutLnk(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory),
    22                Application.ExecutablePath, "我的应用程序""我的应用程序", Application.ExecutablePath);
    23            MessageBox.Show("成功创建快捷方式");
    24        }

    25    }

    26}
  • 相关阅读:
    转载:PHP的session过期设置
    转载:php实现记住密码自动登录
    jQuery方法大全
    转载: IE、FF、Safari、OP不同浏览器兼容报告
    div布局的小心得
    PHP MVC模式在网站架构中的实现分析
    梳理一下 html 中的一些基本概念
    DNN学习笔记代码学习:Null 荣
    DNN学习笔记:DNN类中的ProviderType字段 荣
    在苏州 荣
  • 原文地址:https://www.cnblogs.com/hetonghai/p/1208015.html
Copyright © 2020-2023  润新知