2010-06-12 154 views

回答

3

我發現在谷歌這個答案,網址爲:http://www.geekpedia.com/tutorial125_Create-shortcuts-with-a-.NET-application.html

剛:

WshShell = new WshShellClass(); 

// Create the shortcut 
IWshRuntimeLibrary.IWshShortcut MyShortcut; 

// Choose the path for the shortcut 
MyShortcut = IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(@"C:\MyShortcut.lnk"); 

// Where the shortcut should point to 
MyShortcut.TargetPath = Application.ExecutablePath; 

// Description for the shortcut 
MyShortcut.Description = "Launch My Application"; 

// Location for the shortcut's icon 
MyShortcut.IconLocation = Application.StartupPath + @"\app.ico"; 

// Create the shortcut at the given path 
MyShortcut.Save(); 

只記得添加引用Windows腳本宿主對象模型

+1

這與[重複問題]中給出的答案相同(http://stackoverflow.com/questions/234231/how-do-you-create-an-application-shortcut-lnk-file-in-c-or-淨)。 – 2010-06-12 15:39:18

+0

@Andy這是*不是*重複線程中給出的相同答案。另一個線程使用適當的API - ShellLink COM對象,這個對象被封裝在一個託管包裝器中。 – 2010-06-12 16:16:44

+0

@Ian:也許我應該鏈接到[重複答案](http://stackoverflow.com/questions/234231/how-do-you-create-an-application-shortcut-lnk-file-in-c -or網/ 234243#234243)。唯一的區別在於代碼是從鏈接網站粘貼的。 – 2010-06-12 19:08:41

-2

這裏是我的德爾福代碼:

function CreateShellLink(const szFilename: string; const szDescription: string): IShellLinkA; 
var 
    sl: IShellLinkA; 
begin 
    sl := CreateComObject(CLSID_ShellLink) as IShellLinkA; 
    OleCheck(sl.SetPath(szFilename)); 
    OleCheck(sl.SetDescription(szDescription)); 

    Result := sl; 
end; 

你必須弄清楚從.NET使用Win32 api。

+1

雖然相關,但這對OP沒有什麼幫助...... – 2010-06-12 15:32:17

+0

嗯,這有點幫助,它是正確的做法。 – 2010-06-12 15:56:07

+0

根據什麼適當? – 2010-06-13 15:54:54

相關問題