获取Windows搜索(SystemIndex)的排除扩展名列表
检索Windows搜索索引排除扩展名的替代方案
你遇到的EnumerateExcludedExtensions方法未实现的问题是常见情况,以下是几种可行的替代方案:
方法1:读取注册表项
Windows搜索的排除扩展名分别存储在机器级和用户级注册表路径中:
- 机器级:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Search\Gathering Manager\ExtensionsToExclude - 用户级:
HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows Search\Gathering Manager\ExtensionsToExclude
C#示例代码:
using Microsoft.Win32; using System; class Program { static void Main() { // 读取机器级排除扩展名(需管理员权限) using (RegistryKey machineKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows Search\Gathering Manager\ExtensionsToExclude")) { PrintExcludedExtensions(machineKey, "机器级排除扩展名"); } // 读取用户级排除扩展名 using (RegistryKey userKey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows Search\Gathering Manager\ExtensionsToExclude")) { PrintExcludedExtensions(userKey, "用户级排除扩展名"); } } static void PrintExcludedExtensions(RegistryKey key, string label) { if (key == null) { Console.WriteLine($"{label}: 未找到对应注册表项"); return; } Console.WriteLine($"{label}:"); foreach (string ext in key.GetValueNames()) { Console.WriteLine($" {ext}"); } } }
方法2:通过WMI查询
使用Win32_SearchSetting WMI类可以直接获取搜索设置中的排除扩展名列表,C#示例代码:
using System.Management; using System; class Program { static void Main() { try { ManagementObjectSearcher searcher = new ManagementObjectSearcher( "root\\CIMV2", "SELECT ExcludedExtensions FROM Win32_SearchSetting" ); foreach (ManagementObject obj in searcher.Get()) { string[] excludedExts = obj["ExcludedExtensions"] as string[]; if (excludedExts != null) { Console.WriteLine("排除的扩展名列表:"); foreach (string ext in excludedExts) { Console.WriteLine($" {ext}"); } } } } catch (ManagementException e) { Console.WriteLine($"WMI查询错误: {e.Message}"); } } }
方法3:PowerShell命令行方式
如果不需要编写C#代码,可直接用PowerShell获取:
# 获取全局排除扩展名 Get-WmiObject -Namespace root\CIMV2 -Class Win32_SearchSetting | Select-Object -ExpandProperty ExcludedExtensions # 从注册表读取机器级和用户级排除项 Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows Search\Gathering Manager\ExtensionsToExclude" | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty Name Get-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows Search\Gathering Manager\ExtensionsToExclude" | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty Name
内容的提问来源于stack exchange,提问作者Phil G
相关产品推荐
相关产品推荐

