可能重复:
How do you create an application shortcut (.lnk file) in C# or .Net
您好,
如何在C#中为.exe创建快捷方式的任何线索?
由于
答案 0 :(得分:3)
我在google找到了这个答案: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 :(得分:-2)
这是我的Delphi代码:
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。