Creating a file shortcut (.lnk)

喜你入骨 提交于 2019-11-28 23:14:41

One way to do this is pointed out by Joepro in their answer here:

You'll need to add a COM reference to Windows Scripting Host. As far as i know, there is no native .net way to do this.

WshShellClass wsh = new WshShellClass();
IWshRuntimeLibrary.IWshShortcut shortcut = wsh.CreateShortcut(
    Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\shorcut.lnk") as IWshRuntimeLibrary.IWshShortcut;
shortcut.Arguments = "";
shortcut.TargetPath = "c:\\app\\myftp.exe";
// not sure about what this is for
shortcut.WindowStyle = 1; 
shortcut.Description = "my shortcut description";
shortcut.WorkingDirectory = "c:\\app";
shortcut.IconLocation = "specify icon location";
shortcut.Save();

For .Net 4.0 and above, replace the first line with the following:

 WshShell wsh = new WshShell();

EDIT: This link can help too

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!