WPF 创建桌面快捷键方式

本文详细介绍了如何在C#代码中使用IWshRuntimeLibrary和COM组件WindowsScriptHostObjectModel来创建一个新的桌面快捷方式,包括设置快捷方式的路径、工作目录、描述和图标等属性。
摘要由CSDN通过智能技术生成

引用 IWshRuntimeLibrary; 

引用COM组件:Windows Script Host Object Model

   #region 创建桌面快捷方式
            string exePath = "D:\\ceshi\\demo01.exe";

            // 获取当前可执行文件的路径
            string executablePath = Assembly.GetExecutingAssembly().Location;
            // 获取桌面路径
            string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);

            // 创建快捷方式文件的路径
            string shortcutPath = System.IO.Path.Combine(desktopPath, "GXYLaundry.lnk");

            // 创建 WshShell 对象
            WshShell shell = new WshShell();

            // 创建快捷方式
            IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutPath);

            // 设置快捷方式属性
            shortcut.TargetPath = xiyi_exe;
            shortcut.WorkingDirectory = System.IO.Path.GetDirectoryName(xiyi_exe);
            shortcut.Description = "快捷键";
            shortcut.IconLocation = xiyi_exe; // 使用应用程序图标

            // 保存快捷方式
            shortcut.Save();

            #endregion

  • 9
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值