c# everthing.exe 通信

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;從配置開啟、命令使用到實戰案例與問…