using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;namespace Sci
{// 添加引用 -> com组件 -> Windows Script Host Object Model// Interop.IWshRuntimeLibrary.dllclass ShotCutTool{private static IWshRuntimeLibrary.WshShell shell;/// <summary>/// 为srcFile文件创建快捷方式/// </summary>/// <param name="srcFile">待创建快捷方式的文件</param>/// <param name="linkPath">快捷方式保存完整路径</param>/// <param name="arguments">快捷方式传递的参数信息</param>/// <param name="description">描述</param>/// <param name="hotkey">系统热键</param>/// <param name="iconLocation">快捷方式图标路径</param>public static void CreateShotCut(string srcFile, string linkPath = null, string arguments = null, string description = null, string hotkey = null, string iconLocation = null){if (linkPath == null) linkPath = srcFile;linkPath += ".lnk";if (File.Exists(linkPath)) File.Delete(linkPath); // 删除原有的lnk文件if(shell == null) shell = new IWshRuntimeLibrary.WshShell();IWshRuntimeLibrary.IWshShortcut shotcut = shell.CreateShortcut(linkPath); // 创建一个指定名称路径的lnkshotcut.TargetPath = srcFile; // 待创建链接的原文件if(arguments != null) shotcut.Arguments = arguments; // 传递参数if (description != null) shotcut.Description = description; // 链接描述if (hotkey != null) shotcut.Hotkey = hotkey; // 全局热键, 如:"CTRL+SHIFT+N"if (iconLocation != null) shotcut.IconLocation = iconLocation; // 设置Icon图标shotcut.Save(); // 保存link}/// <summary>/// 获取快捷方式的链接地址/// </summary>/// <param name="linkPath">快捷方式路径</param>/// <returns></returns>public static string GetTargetPath(string linkPath){if (shell == null) shell = new IWshRuntimeLibrary.WshShell();IWshRuntimeLibrary.IWshShortcut shotcut = shell.CreateShortcut(linkPath); // 创建一个指定名称路径的lnkstring targetPath = shotcut.TargetPath;if (targetPath == null) targetPath = "";return targetPath;}}
}
详细解决方案
C# 创建快捷方式、获取快捷方式链接地址
热度:70 发布时间:2024-01-10 07:04:24.0
相关解决方案
- 打包时通过自定义安装生成的 快捷方式 怎么在开始-程序中创建
- ftp 中建立 文件夹 快捷方式
- 删掉Android4.0中与电话有关的小部件(快捷方式)
- android运用-创建快捷方式
- IDEA 自动生成作者等备注信息,快捷方式
- Linux Shell简介——自动补齐/命令行的历史记录/编辑命令行/可用的 Shell 快捷方式
- Linux中的“快捷方式”:ln
- 如何手动创建 Internet 快捷方式
- C# 创建快捷方式、获取快捷方式链接地址
- Android项目-快捷方式
- Linux学习6之 快捷方式
- vscode 快捷方式
- Android 快捷方式 shortcuts 使用
- Android - 快捷方式