可能重複:
How do you create an application shortcut (.lnk file) in C# or .Net應用程序快捷方式
嗨,
如何在C#中的.exe創建快捷方式的任何線索?
感謝
可能重複:
How do you create an application shortcut (.lnk file) in C# or .Net應用程序快捷方式
嗨,
如何在C#中的.exe創建快捷方式的任何線索?
感謝
我發現在谷歌這個答案,網址爲: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腳本宿主對象模型
這與[重複問題]中給出的答案相同(http://stackoverflow.com/questions/234231/how-do-you-create-an-application-shortcut-lnk-file-in-c-or-淨)。 – 2010-06-12 15:39:18
@Andy這是*不是*重複線程中給出的相同答案。另一個線程使用適當的API - ShellLink COM對象,這個對象被封裝在一個託管包裝器中。 – 2010-06-12 16:16:44
@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
這裏是我的德爾福代碼:
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。
雖然相關,但這對OP沒有什麼幫助...... – 2010-06-12 15:32:17
嗯,這有點幫助,它是正確的做法。 – 2010-06-12 15:56:07
根據什麼適當? – 2010-06-13 15:54:54
您是否試過Google? http://www.google.com/search?q=c%23+create+shortcut,數十項結果。 – 2010-06-12 15:31:28