在目录中创建应用程序快捷方式 [英] Creating application shortcut in a directory
本文介绍了在目录中创建应用程序快捷方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用 C# 或 .NET 框架创建应用程序快捷方式(.lnk 文件)?
How do you create an application shortcut (.lnk file) in C# or using the .NET framework?
结果将是指定应用程序或 URL 的 .lnk 文件.
The result would be a .lnk file to the specified application or URL.
推荐答案
这并不像我想要的那么简单,但是有一个很棒的课堂调用 ShellLink.cs 在vbAccelerator
It's not as simple as I'd have liked, but there is a great class call ShellLink.cs at vbAccelerator
此代码使用互操作,但不依赖 WSH.
This code uses interop, but does not rely on WSH.
使用这个类,创建快捷方式的代码是:
Using this class, the code to create the shortcut is:
private static void configStep_addShortcutToStartupGroup()
{
using (ShellLink shortcut = new ShellLink())
{
shortcut.Target = Application.ExecutablePath;
shortcut.WorkingDirectory = Path.GetDirectoryName(Application.ExecutablePath);
shortcut.Description = "My Shorcut Name Here";
shortcut.DisplayMode = ShellLink.LinkDisplayMode.edmNormal;
shortcut.Save(STARTUP_SHORTCUT_FILEPATH);
}
}
这篇关于在目录中创建应用程序快捷方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文