Hero is coming back

风吹呀吹

风会指引你前进的方向

C# 创建快捷方式

/// <summary>
/// 创建快捷方式
/// </summary>
/// <param name="FileName">文件名 -不包含后缀</param>
/// <param name="exePath">exe的全路径</param>
/// <param name="iconPath">快捷方式的图标</param>    
public static bool CreateDesktopShortcut(string FileName, string exePath,string iconPath)
{
    try
    {
        string deskTop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\";
        if (System.IO.File.Exists(deskTop + FileName + ".lnk"))  //
        {
            System.IO.File.Delete(deskTop + FileName + ".lnk");//删除原来的桌面快捷键方式
        }
        WshShell shell = new WshShell();

        //快捷键方式创建的位置、名称
        IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(deskTop + FileName + ".lnk");
        shortcut.TargetPath = exePath; //目标文件
                                       //该属性指定应用程序的工作目录,当用户没有指定一个具体的目录时,快捷方式的目标应用程序将使用该属性所指定的目录来装载或保存文件。
        shortcut.WorkingDirectory = System.Environment.CurrentDirectory;
        shortcut.WindowStyle = 1; //目标应用程序的窗口状态分为普通、最大化、最小化【1,3,7】
        shortcut.Description = FileName; //描述
        shortcut.IconLocation = iconPath;
        shortcut.Arguments = "";
        //shortcut.Hotkey = "CTRL+ALT+F11"; // 快捷键
        shortcut.Save(); //必须调用保存快捷才成创建成功
        return true;
    }
    catch (Exception)
    {
        return false;
    }
}
posted @ 2022-07-06 15:35  风吹呀吹  阅读(876)  评论(0编辑  收藏  举报