C# winform 创建快捷方式
using System;
using IWshRuntimeLibrary;
using System.IO;
namespace UavSystem.Common
{
public class ShortcutCreator
{
//需要引入IWshRuntimeLibrary,搜索Windows Script Host Object Model
//需要引用Microsoft.Csharp
/// <summary>
/// 创建快捷方式
/// </summary>
/// <param name="directory">快捷方式所处的文件夹</param>
/// <param name="shortcutName">快捷方式名称</param>
/// <param name="targetPath">目标路径</param>
/// <param name="description">描述</param>
/// <param name="iconLocation">图标路径,格式为"可执行文件或DLL路径, 图标编号",
/// 例如System.Environment.SystemDirectory + "\\" + "shell32.dll, 165"</param>
/// <remarks></remarks>
public static void CreateShortcut(string directory, string shortcutName, string targetPath,
string description = null, string iconLocation = null)
{
if (!System.IO.Directory.Exists(directory))
{
System.IO.Directory.CreateDirectory(directory);
}
string shortcutPath = Path.Combine(directory, string.Format("{0}.lnk", shortcutName));
WshShell shell = new WshShell();
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutPath);//创建快捷方式对象
shortcut.TargetPath = targetPath;//指定目标路径
shortcut.WorkingDirectory = Path.GetDirectoryName(targetPath);//设置起始位置
shortcut.WindowStyle = 1;//设置运行方式,默认为常规窗口
shortcut.Description = description;//设置备注
shortcut.IconLocation = string.IsNullOrWhiteSpace(iconLocation) ? targetPath : iconLocation;//设置图标路径
shortcut.Save();//保存快捷方式
}
/// <summary>
/// 创建桌面快捷方式
/// </summary>
/// <param name="shortcutName">快捷方式名称</param>
/// <param name="targetPath">目标路径</param>
/// <param name="description">描述</param>
/// <param name="iconLocation">图标路径,格式为"可执行文件或DLL路径, 图标编号"</param>
/// <remarks></remarks>
public static void CreateShortcutOnDesktop(string shortcutName, string targetPath, string description = null, string iconLocation = null)
{
string desktop = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);//获取桌面文件夹路径
CreateShortcut(desktop, shortcutName, targetPath, description, iconLocation);
}
}
}
C# winform 创建快捷方式的更多相关文章
- winform创建快捷方式
/// <summary> /// 创建快捷方式 /// </summary> public class Lnk { /// <summary> /// 创建快捷方 ...
- winform创建桌面快捷方式
//引用IWshRuntimeLibrary COM组件-Windows Script Host Object Model /// <summary> /// 创建快捷方式的类 /// & ...
- 使用C#创建快捷方式
在Windows中创建快捷方式很简单,直接用右键点击文件或文件夹,选择创建快捷方式即可.如果想用C#代码的方式创建,就没有那么方便了,因为.NET框架没有提供直接创建快捷方式的方法. 首先我们看一下快 ...
- [No000004]在WIN7/8任务栏创建快捷方式
在XP时代,有一个快速启动栏,创建快捷方式只需要把快捷方式放在“%AppData%\Roaming\Microsoft\Internet Explorer\Quick Launch”文件夹下即可,如果 ...
- c# 纯代码方式创建快捷方式
using System; using System.Collections.Generic; using System.Text; using Microsoft.Win32; using Syst ...
- C#两种创建快捷方式的方法
C#两种创建快捷方式的方法http://www.cnblogs.com/linmilove/archive/2009/06/10/1500989.html
- Arduino1.7.10在Ubuntu下创建快捷方式
从官网下载的arduino1.7.10版本没有快捷方式只有可执行文件arduino,通过下面的方法可以创建快捷方式 打开链接:http://www.easyicon.net/1171938-ardui ...
- 为apache与mysql创建快捷方式
为apache与mysql创建快捷方式 1)为apache创建快捷方式(软链接) 以后我们就可以在终端的任一位置,使用apachectl start|stop|restart 2)为mysql创建 ...
- Ubuntu系统应用程序创建快捷方式的方法
大家安装了最新版的Ubuntu 14.0系统之后可能觉得很不习惯,因为Ubuntu的桌面干干净净没有任何快捷方式,任务栏的图标拖不下来,右键点击程序图标也没有创建快捷方式的菜单选项: 那如何把自己经常 ...
随机推荐
- DataSnap Mobile Client Tutorial
One of my customers was having some difficulty following the DataSnap tutorial which can be found he ...
- linux 设备驱动程序中的一些关联性思考
首先,个人感觉设备驱动程序与应用程序中的文件操作隔得有点远,用户空间不论是直接使用系统调用还是库函数都是通过系统调用的接口进入内核空间代码的.但是看过一个博客的分析整个过程,感觉中间层太过麻烦,必须经 ...
- 微信公众号菜单与应用交互session
http://www.cnblogs.com/yank/p/3476874.html http://blog.csdn.net/zmhawk/article/details/43671195 http ...
- Ubuntu下如何安装并使用Objective-C
Objective-C是本人用过的最佳类C.面向对象的编程语言.Objective-C与标准C完美兼容,而在此基础上又加上了将面向对象的基础概念诠释得最好的SmallTalk元素,使得它既简洁.又灵活 ...
- SDUT oj 选拔赛1 迷之好奇
迷之好奇 Time Limit: 2000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 FF得到了一个有n个数字的集合.不要问我为什么,有钱,任性. FF很好奇 ...
- POJ3252 Round Numbers —— 数位DP
题目链接:http://poj.org/problem?id=3252 Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Su ...
- POJ1077 Eight —— 正向BFS
主页面:http://www.cnblogs.com/DOLFAMINGO/p/7538588.html 代码一:以数组充当队列,利用结构体中的pre追溯上一个状态在数组(队列)中的下标: #incl ...
- hiho Mission Impossible 6(模拟 未提交验证。。)
题意:模拟文本操作 思路:模拟 #include<iostream> #include<stdio.h> #include<string.h> using name ...
- Android多国语言文件夹汇总
Arabic, Egypt (ar-rEG) —————————–阿拉伯语,埃及 Arabic, Israel (ar-rIL) ——————————-阿拉伯语,以色列 Bulgarian, Bulg ...
- (转)Vim十大必备插件
原文地址:http://www.open-open.com/lib/view/open1414227253419.html Vim十大必备插件 Taglist taglist是一个用于显示定位程序中各 ...