• C# 创建桌面快捷方式


    /// <summary>
    /// 创建桌面快捷方式
    /// </summary>
    /// <param name="deskTop">桌面的路径</param>
    /// <param name="FileName">文件的名称</param>
    /// <param name="exePath">EXE的路径</param>
    /// <returns>成功或失败</returns>
    public bool CreateDesktopShortcut(string deskTop, string FileName, string exePath)
    {
        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 = exePath + "\logo.ico";  //快捷方式图标
            shortcut.Arguments = "";
            //shortcut.Hotkey = "CTRL+ALT+F11"; // 快捷键
            shortcut.Save(); //必须调用保存快捷才成创建成功
            return true;
        }
        catch (Exception)
        {
            return false;
        }
    }
  • 相关阅读:
    [笔记] 什么是欠采样?
    [笔记] Frequncy Divider
    [笔记] SDRAM读写控制
    能力去激活
    一个实用的SQL
    有用的SQL 语句(不断更新)
    javascript 与服务器端交互的一个小问题
    Javascript 验证码
    几个文本编辑器
    ASP.NET验证码(3种)
  • 原文地址:https://www.cnblogs.com/flamegreat/p/12195752.html
Copyright © 2020-2023  润新知