現將C#創(chuàng )建快捷方式總結如下:
1、快捷方式包含如下數據:
·快捷方式的名字
·快捷方式所指向的目標所在的位置
·快捷方式所指向的目標的工作目錄
·激活該快捷方式的熱鍵
·快捷方式所指向的目標運行時(shí)的窗口風(fēng)格(普通、最大化和最小化)
·該快捷方式的描述性文字
·快捷方式的圖標所在的位置
2、在工程中選擇 COM 選項卡并選擇 Windows Script Host Object Model。
如圖:
3、代碼如下:using System;
using System.Collections.Generic;
using System.Collections;
using System.IO;
using System.Reflection;
using IWshRuntimeLibrary;
namespace Test
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
//創(chuàng )建快捷方式
//建立對象
WshShell shell = new WshShell();
//生成快捷方式文件,指定路徑及文件名
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(
Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) +
"\\" + "sunlunjun.lnk");
//快捷方式指向的目標
shortcut.TargetPath = Path.Combine(System.Environment.CurrentDirectory, "myService.exe");
//起始目錄
shortcut.WorkingDirectory = System.Environment.CurrentDirectory;
//窗口類(lèi)型
shortcut.WindowStyle = 1;
//描述
shortcut.Description = "my Application";
//圖標
shortcut.IconLocation = System.Environment.SystemDirectory + "\\" + "shell32.dll, 165";
//保存,注意一定要保存,否則無(wú)效
shortcut.Save();
}