c# 快捷方式

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using IWshRuntimeLibrary;
using System.IO;

namespace WindowsApplication28
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{

//string targetPath = Application.StartupPath;
//string savePath = "C:\\Documents and Settings\\All Users\\「开始」菜单\\程序\\启动\\321";
//string saveName = "123.exe";

//IWshRuntimeLibrary.IWshShell shell_class = new IWshRuntimeLibrary.IWshShell_ClassClass();
//IWshRuntimeLibrary.IWshShortcut shortcut = null;
//if (!Directory.Exists(targetPath))
// return;
////if (!Directory(savePath))
// Directory.CreateDirectory(savePath);
//try
//{
// shortcut = shell_class.CreateShortcut(savePath + @"/" + saveName + ".lnk") as IWshRuntimeLibrary.IWshShortcut;
// shortcut.TargetPath = targetPath;
// shortcut.Save();
// MessageBox.Show("创佳快捷方式成功!");
//}
//catch (Exception ex)
//{
// MessageBox.Show("创佳快捷方式失败!");
//}

WshShell shell = new WshShell();
//IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(
// Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) +
// "\\" + "我的快捷方式.lnk"
//);
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(
"C:\\Documents and Settings\\All Users\\「开始」菜单\\程序\\启动\\我的快捷方式.lnk");
shortcut.TargetPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
shortcut.WorkingDirectory = System.Environment.CurrentDirectory;
shortcut.WindowStyle = 1;
shortcut.Description = "Launch Allen’s Application";
shortcut.IconLocation = System.Environment.SystemDirectory + "\\" + "shell32.dll, 165";
shortcut.Save();
}
}
}

posted @ 2012-07-23 07:47  雷盼  阅读(267)  评论(0编辑  收藏  举报