uses
Windows, SysUtils, ComObj, ShlObj;
Windows, SysUtils, ComObj, ShlObj;
procedure CreateShortcutOnDesktop(const TargetPath, ShortcutName: string);
var
WSHShell: Variant;
Shortcut: Variant;
DesktopPath: array[0..MAX_PATH] of Char;
begin
// 初始化 WSHShell
WSHShell := CreateOleObject('WScript.Shell');
// 獲取桌面路徑
SHGetSpecialFolderPath(0, DesktopPath, CSIDL_DESKTOP, False);
// 創建捷徑對象
Shortcut := WSHShell.CreateShortcut(IncludeTrailingPathDelimiter(DesktopPath) + ShortcutName + '.lnk');
// 設置捷徑目標路徑和描述
Shortcut.TargetPath := TargetPath;
Shortcut.Description := 'Shortcut to ' + ShortcutName;
// 保存捷徑
Shortcut.Save;
end;
var
WSHShell: Variant;
Shortcut: Variant;
DesktopPath: array[0..MAX_PATH] of Char;
begin
// 初始化 WSHShell
WSHShell := CreateOleObject('WScript.Shell');
// 獲取桌面路徑
SHGetSpecialFolderPath(0, DesktopPath, CSIDL_DESKTOP, False);
// 創建捷徑對象
Shortcut := WSHShell.CreateShortcut(IncludeTrailingPathDelimiter(DesktopPath) + ShortcutName + '.lnk');
// 設置捷徑目標路徑和描述
Shortcut.TargetPath := TargetPath;
Shortcut.Description := 'Shortcut to ' + ShortcutName;
// 保存捷徑
Shortcut.Save;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
// 創建 A.EXE 的捷徑到桌面
CreateShortcutOnDesktop('C:\path\to\A.EXE', 'A.EXE Shortcut');
end;
沒有留言:
張貼留言