.lnk 檔案,包含:名稱、目標路徑、工作目錄、熱鍵、視窗樣式、描述、圖示路徑。
專案右鍵 → 加入參考 → COM 標籤 → Windows Script Host Object Model
using System;
using IWshRuntimeLibrary;
class Program
{
static void Main(string[] args)
{
WshShell shell = new WshShell();
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(
Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)
+ "\\" + "Allen's Application.lnk");
shortcut.TargetPath = Assembly.GetExecutingAssembly().Location;
shortcut.WorkingDirectory = Environment.CurrentDirectory;
shortcut.WindowStyle = 1; // 1=正常, 3=最大化, 7=最小化
shortcut.Description = "Launch Allen's Application";
shortcut.IconLocation = Environment.SystemDirectory + "\\shell32.dll, 165";
shortcut.Save();
}
}
| 屬性 | 用途 |
|---|---|
| TargetPath | 目標執行檔完整路徑 |
| WorkingDirectory | 啟動工作目錄 |
| WindowStyle | 1=正常, 3=最大化, 7=最小化 |
| Description | 滑鼠懸停提示文字 |
| IconLocation | 圖示檔路徑 + 索引 (shell32.dll 內建圖示) |
| Hotkey | 熱鍵 (如 "Ctrl+Alt+A") |
| Arguments | 命令列參數 |