可能重复:
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