C#创建快捷方式
2005-03-12 12:49
369 查看
这几天在做一个Web项目的安装程序,在制作过程有些技巧发现,贴出来共享一下
首先添加以下引用:COM下Windows Script Host Object Model,然后可以通过以下方法创建快捷方式。
using System.Runtime.InteropServices;
using IWshRuntimeLibrary;
string app = "http://localhost/TrainManage/Default.aspx";
string location1 = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Favorites) + "\\培训教学教务管理系统.url";
string location2 = System.Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory) + "\\培训教学教务管理系统.url";
string location3 = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Programs) + "\\培训教学教务管理系统.url";
try
{
// Create a Windows Script Host Shell class
IWshShell_Class shell = new IWshShell_ClassClass();
// Define the shortcut file
IWshURLShortcut shortcut = shell.CreateShortcut(location1) as IWshURLShortcut;
shortcut.TargetPath = app;
// Save it
shortcut.Save();
shortcut = shell.CreateShortcut(location2) as IWshURLShortcut; shortcut.TargetPath = app;
// Save it
shortcut.Save();
shortcut = shell.CreateShortcut(location3) as IWshURLShortcut;
shortcut.TargetPath = app;
// Save it
shortcut.Save();
}
catch(COMException ex)
{
Console.WriteLine(ex.Message);
首先添加以下引用:COM下Windows Script Host Object Model,然后可以通过以下方法创建快捷方式。
using System.Runtime.InteropServices;
using IWshRuntimeLibrary;
string app = "http://localhost/TrainManage/Default.aspx";
string location1 = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Favorites) + "\\培训教学教务管理系统.url";
string location2 = System.Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory) + "\\培训教学教务管理系统.url";
string location3 = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Programs) + "\\培训教学教务管理系统.url";
try
{
// Create a Windows Script Host Shell class
IWshShell_Class shell = new IWshShell_ClassClass();
// Define the shortcut file
IWshURLShortcut shortcut = shell.CreateShortcut(location1) as IWshURLShortcut;
shortcut.TargetPath = app;
// Save it
shortcut.Save();
shortcut = shell.CreateShortcut(location2) as IWshURLShortcut; shortcut.TargetPath = app;
// Save it
shortcut.Save();
shortcut = shell.CreateShortcut(location3) as IWshURLShortcut;
shortcut.TargetPath = app;
// Save it
shortcut.Save();
}
catch(COMException ex)
{
Console.WriteLine(ex.Message);
相关文章推荐
- C#创建快捷方式与添加网页到收藏夹
- c# 纯代码方式创建快捷方式
- C#两种创建快捷方式的方法
- 用C# 创建快捷方式
- C#创建桌面快捷方式 和 开机启动
- 在 .NET 中创建快捷方式 [C#]
- 如何使用C#操作快捷方式(获取快捷方式属性、创建快捷方式)
- 【转】在C#2005中创建快捷方式
- C#创建桌面快捷方式
- 如何使用C#代码创建快捷方式文件详解
- C# 创建快捷方式
- C#如何编程在桌面创建快捷方式
- 创建桌面快捷方式+设置开机启动代码[C#、WinForm]
- c#通过纯代码创建桌面快捷方式、创建程序菜单项、将网页添加到收藏夹
- C# 创建一个application的桌面快捷方式
- 在 .NET 中创建快捷方式 [C#]
- C#创建一个文件的快捷方式
- C#入门学习-----菜单应用(添加剂快捷方式、设置菜单项是否可用、修改菜单字体、创建级联菜单、级联菜单的动态合并)
- 用C# 创建快捷方式
- C# 创建桌面快捷方式【转】