1 获取everthing进程  调用 Everything 搜索创建SearchWithEverything函数

using Microsoft.Win32;
using System;
using System.Diagnostics;
using System.IO;
using System.Management;
using System.Text;class EverythingHelper
{// 方法 1:从进程获取路径public static string GetEverythingPathFromRunningProcess(){Process[] processes = Process.GetProcessesByName("Everything");if (processes.Length == 0){return null; // Everything 未运行}try{return processes[0].MainModule.FileName;}catch{return null; // 权限不足}}// 方法 2:从 WMI 获取路径(更可靠)public static string GetEverythingPathFromWMI(){string query = "SELECT ExecutablePath FROM Win32_Process WHERE Name = 'Everything.exe'";try{using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(query))using (ManagementObjectCollection results = searcher.Get()){if (results.Count == 0) return null;foreach (ManagementObject process in results){try{object pathObj = process["ExecutablePath"];if (pathObj != null){string exePath = pathObj.ToString();if (!string.IsNullOrWhiteSpace(exePath) && File.Exists(exePath)){return exePath;}}}catch (ManagementException ex){// 记录错误或忽略(权限不足等)Debug.WriteLine($"WMI Access Error: {ex.Message}");}}}}catch (Exception ex){Debug.WriteLine($"WMI Query Failed: {ex.Message}");}return null;}// 方法 3:从注册表获取public static string GetEverythingPathFromRegistry(){using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Everything")){if (key != null){object installLocationObj = key.GetValue("InstallLocation");string installLocation = installLocationObj?.ToString(); // 安全转换if (!string.IsNullOrEmpty(installLocation)){string exePath = Path.Combine(installLocation, "Everything.exe");if (File.Exists(exePath)) return exePath;}}}return null;}// 获取 Everything 选中的文件和目录列表// 版本检测:需要 Everything 1.4.1+public static bool CheckEverythingVersion(){try{string exePath = FindEverythingExe();var versionInfo = FileVersionInfo.GetVersionInfo(exePath);return versionInfo.FileMajorPart > 1 ||(versionInfo.FileMajorPart == 1 && versionInfo.FileMinorPart >= 4);}catch{return false;}}// 增强版获取选中项(带状态反馈)public static (List<string> items, string message) GetSelectedItemsWithStatus(){try{// 检查 Everything 是否运行if (Process.GetProcessesByName("Everything").Length == 0)return (new List<string>(), "Everything 未运行");if (!CheckEverythingVersion())return (new List<string>(), "需要 Everything 1.4.1 或更高版本");var items = new List<string>();string exePath = FindEverythingExe();using (Process process = new Process()){process.StartInfo = new ProcessStartInfo{FileName = exePath,Arguments = "-export-selected-items-to-stdout",UseShellExecute = false,RedirectStandardOutput = true,CreateNoWindow = true,StandardOutputEncoding = Encoding.UTF8};process.Start();// 异步读取输出while (!process.StandardOutput.EndOfStream){string line = process.StandardOutput.ReadLine()?.Trim();if (!string.IsNullOrEmpty(line) && (File.Exists(line) || Directory.Exists(line))){items.Add(line);}}if (!process.WaitForExit(3000)) // 最多等待3秒{process.Kill();return (items, $"获取超时,已找到 {items.Count} 个有效项");}}return items.Count > 0? (items, $"成功获取 {items.Count} 个选中项"): (items, "Everything 中没有选中的有效文件/目录");}catch (Exception ex){return (new List<string>(), $"获取失败: {ex.Message}");}}// 显示选中项在 RichTextBox(带格式)public static void DisplaySelectedItems(RichTextBox box){var (items, status) = GetSelectedItemsWithStatus();box.Clear();box.SelectionColor = Color.Blue;box.AppendText(status + "\n\n");for (int i = 0; i < items.Count; i++){// 序号box.SelectionColor = Color.Green;box.AppendText($"{i + 1}. ");// 路径类型bool isDir = Directory.Exists(items[i]);box.SelectionColor = isDir ? Color.Orange : Color.Black;box.AppendText(isDir ? "[目录] " : "[文件] ");// 路径box.SelectionColor = Color.Black;box.AppendText(items[i] + "\n");}}// 综合查找public static string FindEverythingExe(){// 1. 尝试从运行进程获取string exePath = GetEverythingPathFromWMI() ?? GetEverythingPathFromRunningProcess();if (exePath != null) return exePath;// 2. 尝试从注册表获取exePath = GetEverythingPathFromRegistry();if (exePath != null) return exePath;// 3. 尝试默认路径string[] commonPaths ={@"C:\Program Files\Everything\Everything.exe",@"C:\Program Files (x86)\Everything\Everything.exe",Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Everything", "Everything.exe")};foreach (string path in commonPaths){if (File.Exists(path)) return path;}// 4. 让用户手动选择OpenFileDialog openFileDialog = new OpenFileDialog{Title = "请选择 Everything.exe",Filter = "Everything.exe|Everything.exe|所有文件 (*.*)|*.*",InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)};if (openFileDialog.ShowDialog() == DialogResult.OK)  // 不是 true,而是 DialogResult.OK{return openFileDialog.FileName;}throw new FileNotFoundException("未找到 Everything.exe。");}// 调用 Everything 搜索public static void SearchWithEverything(string query){string everythingExe = FindEverythingExe();Process.Start(everythingExe, $"-s \"{query}\"");}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.pswp.cn/bicheng/91512.shtml
繁体地址,请注明出处:http://hk.pswp.cn/bicheng/91512.shtml
英文地址,请注明出处:http://en.pswp.cn/bicheng/91512.shtml

如若内容造成侵权/违法违规/事实不符,请联系英文站点网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Gitee:中国企业级DevOps平台的本土化突围之路

Gitee&#xff1a;中国企业级DevOps平台的本土化突围之路 在国内数字化转型浪潮下&#xff0c;DevOps平台作为企业研发效能提升的核心引擎&#xff0c;正在经历从工具到生态的全面升级。作为国内领先的一站式DevOps解决方案&#xff0c;Gitee凭借其本土化优势与全链路服务能力&…

C++法则22:运算符 ::* 和 ->* 和 ::* 是独特的整体运算符,是不可分的。

C法则22&#xff1a;运算符 ::* 和 ->* 和 ::* 是独特的整体运算符&#xff0c;是不可分的。1. ::*&#xff08;成员指针声明符&#xff09;作用&#xff1a;用于声明一个指向类成员的指针。语法&#xff1a;ReturnType (ClassName::*pointerName) &ClassName::MemberN…

Linux系统管理习题

Linux 系统管理练习题 1.请为此虚拟机配置以下网络参数&#xff1a; 1&#xff09;主机名&#xff1a;chenyu.example.com &#xff08;将chenyu改成自己名字的全拼&#xff09; 2&#xff09;IP 地址&#xff1a;192.168.100.100/24 3&#xff09;默认网关&#xff1a;192.168…

SQL166 每天的日活数及新用户占比

SQL166 每天的日活数及新用户占比 题目理解 本SQL查询旨在分析用户活跃数据&#xff0c;计算两个关键指标&#xff1a; 每日活跃用户数(DAU)每日新增用户占比(新用户占活跃用户的比例) 解题思路 1. 数据准备阶段 首先我们需要获取所有用户的活跃记录&#xff0c;包括&…

【33】C# WinForm入门到精通 ——表格布局器TableLayoutPanel【属性、方法、事件、实例、源码】

WinForm 是 Windows Form 的简称&#xff0c;是基于 .NET Framework 平台的客户端&#xff08;PC软件&#xff09;开发技术&#xff0c;是 C# 语言中的一个重要应用。 .NET 提供了大量 Windows 风格的控件和事件&#xff0c;可以直接拿来使用。 本专栏内容是按照标题序号逐渐…

uv使用教程

以下是使用 Python 包管理工具 uv 的常见命令指南。uv 是由 Astral&#xff08;Ruff 的开发者&#xff09;开发的高性能 Python 包安装器和解析器&#xff0c;旨在替代 pip 和 pip-tools&#xff1a; 1. 安装 uv uv官网仓库 # Linux/macOS curl -Ls https://astral.sh/uv/in…

SpringBoot3.x入门到精通系列:1.1 简介与新特性

SpringBoot 3.x 简介与新特性 &#x1f4d6; 什么是SpringBoot SpringBoot是由Pivotal团队提供的全新框架&#xff0c;其设计目的是用来简化Spring应用的初始搭建以及开发过程。SpringBoot集成了大量常用的第三方库配置&#xff0c;SpringBoot应用中这些第三方库几乎可以零配…

二、搭建springCloudAlibaba2021.1版本分布式微服务-Nacos搭建及服务注册和配置中心

nacos介绍 1、Nacos简介 Nacos 是阿里巴巴推出来的一个新开源项目&#xff0c;这是一个更易于构建云原生应用的动态服务发现、配置管理和服务管理平台。 Nacos 致力于帮助您发现、配置和管理微服务。Nacos 提供了一组简单易用的特性集&#xff0c;帮助您快速实现动态服务发现、…

浅谈物联网嵌入式程序开发源码技术方案

在物联网蓬勃发展的时代&#xff0c;嵌入式程序作为连接硬件与软件的桥梁&#xff0c;发挥着至关重要的作用。以“边缘智能 云协同”为核心&#xff0c;为工业、医疗、家居、农业、智慧城市五大场景提供稳定、低功耗、可扩展的物联网终端与平台一体化解决方案。以下董技叔软件…

【笔记】重学单片机(51)

为学习嵌入式做准备&#xff0c;重新拿起51单片机学习。此贴为学习笔记&#xff0c;仅记录易忘点&#xff0c;实用理论基础&#xff0c;并不是0基础。 资料参考&#xff1a;清翔零基础教你学51单片机 51单片机学习笔记1. C语言中的易忘点1.1 数据类型1.2 位运算符1.3 常用控制语…

C++现代Redis客户端库redis-plus-plus详解

&#x1f680; C现代Redis客户端库redis-plus-plus详解&#xff1a;告别繁琐的hiredis&#xff0c;拥抱现代C的Redis操作 &#x1f4c5; 更新时间&#xff1a;2025年07月28日 &#x1f3f7;️ 标签&#xff1a;C | Redis | redis-plus-plus | 现代C | 后端开发 文章目录&#x…

Redis存储原理与数据模型(上)

一、Redis数据模型 1.1、查看Redis数据定义&#xff1a; typedef struct redisDb {kvstore *keys; /* The keyspace for this DB 指向键值存储的指针&#xff0c;用于快速访问和修改数据库中的键值对*/kvstore *expires; /* Timeout of keys with a t…

视频生成模型蒸馏的方法

1.fastvideo https://github.com/hao-ai-lab/FastVideohttps://github.com/hao-ai-lab/FastVideo Distillation support Recipes for video DiT, based on PCM. Support distilling/finetuning/inferencing state-of-the-art open video DiTs: 1. Mochi 2. Hunyuan. 2.l

【mysql】—— mysql中的timestamp 和 datetime(6) 有什么区别,为什么有的地方不建议使用timestamp

在 MySQL 中,TIMESTAMP 和 DATETIME(6) 都是用于存储日期和时间的数据类型,但它们在存储范围、时区处理、存储方式等方面有显著区别。 1. 核心区别对比 特性 TIMESTAMP DATETIME(6) 存储范围 1970-01-01 00:00:01 UTC ~ 2038-01-19 03:14:07 UTC(受限于 32 位时间戳) 1000…

前端下载文件相关

1、下载 ‘Content-Type‘: ‘application/octet-stream‘ 的文件 当后端返回的响应头中 Content-Type 为 application/octet-stream 时&#xff0c;表示这是一个二进制流文件&#xff0c;浏览器无法直接展示&#xff0c;需要前端处理后下载到本地。 通过请求获取二进制数据…

代码随想录算法训练营第五十六天|动态规划part6

108.冗余连接 题目链接&#xff1a;108. 冗余的边 文章讲解&#xff1a;代码随想录 思路&#xff1a; 题意隐含 只有一个冗余边 #include <iostream> #include <vector> using namespace std; int n1001; vector<int>father(n,0);void init(){for(int i0;…

智能体通信协议

智能体通信协议A2AACPANPAgoraagents.jsonLMOSAITPA2A A2A官方文档&#xff1a;https://www.a2aprotocol.net/docs/introduction 开源代码和详细规范&#xff1a;https://github.com/google/A2A ACP ACP官方文档&#xff1a;https://acp.agentunion.cn ANP ANP官方文档&am…

QT交叉编译环境配置

QT交叉编译环境配置1 配置交叉编译工具链1.1 解压 放到/opt中1.2 使用环境变量1.2.1 设置成永久的环境变量1.2.2 临时环境变量1.3 安装编译需要的软件2 编译tslib库&#xff08;如果不需要触摸屏直接跳过&#xff09;3. 编译qt3.1 编译源码3.2 设置QCreator4 说明4.1 关于编译器…

【Android】【Java】一款简单的文本/图像加解密APP

写在前面 之前写过一篇博客,名为《【Java编程】【计算机视觉】一种简单的图片加/解密算法》,介绍了用Java在电脑上对图片进行简单的加密和解密操作,见链接: 文章链接 但是,文中所描述的算法在实际操作当中,存在严重的噪音(图像失真)的问题(且原因不明),本次经笔者研…

技术笔记 | Ubuntu 系统 OTA 升级全流程详解

前言&#xff1a;在嵌入式系统设备管理中&#xff0c;OTA&#xff08;Over-The-Air&#xff09;升级是实现设备远程维护、功能迭代的核心能力。本文基于 Ubuntu 系统环境&#xff0c;详细拆解 updateEngine 工具的 OTA 升级方案&#xff0c;从配置开启、命令使用到实战案例与问…