现将C#创建快捷方式总结如下:
1、快捷方式包含如下数据:
·快捷方式的名字
·快捷方式所指向的目标所在的位置
·快捷方式所指向的目标的工作目录
·激活该快捷方式的热键
·快捷方式所指向的目标运行时的窗口风格(普通、最大化和最小化)
·该快捷方式的描述性文字
·快捷方式的图标所在的位置
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() { //创建快捷方式 //建立对象 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; //窗口类型 shortcut.WindowStyle = 1; //描述 shortcut.Description = "my Application"; //图标 shortcut.IconLocation = System.Environment.SystemDirectory + "\\" + "shell32.dll, 165"; //保存,注意一定要保存,否则无效 shortcut.Save(); |