c# 快捷方式 ShortCutHelper
public static class ShortCutHelper
{
public static string linkTilte = Assembly.GetExecutingAssembly().GetName().Name;
public static string lnkFullPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory),
linkTilte + ".lnk");
/// <summary>
/// 给当前程序创建快捷方式
/// </summary>
/// <param name="lnkFullPath">快捷方式绝对路径</param>
/// <param name="startupArgs">快捷方式启动参数</param>
public static void CreateShortcut()
{
string exeName = $"{Assembly.GetExecutingAssembly().GetName().Name}.exe";
var exeDir = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
var shellType = Type.GetTypeFromProgID("WScript.Shell");
dynamic shell = Activator.CreateInstance(shellType);
var shortcut = shell.CreateShortcut(lnkFullPath);
// 工作目录和目标路径可以自由指定,注意TargetPath必须是exe的绝对路径
shortcut.WorkingDirectory = exeDir;
shortcut.TargetPath = Path.Combine(exeDir, exeName);
shortcut.Arguments = "";
shortcut.Save();
}
public static bool Exists()
{
return File.Exists(lnkFullPath);
}
}
留待后查,同时方便他人
联系我:renhanlinbsl@163.com
联系我:renhanlinbsl@163.com