以编程方式阻止 Vista 桌面搜索 (WDS) 对映射网络驱动器上的 pst 文件建立索引

发布于 2024-08-28 21:19:48 字数 580 浏览 5 评论 0原文

经过几天的多次尝试,我没有找到任何 100% 的解决方案来解决这个问题。 我的搜索和调查范围:

  1. 直接访问注册表: HKLM\SOFTWARE\Microsoft\Windows Search\CrawlScopeManager\Windows\SystemIndex\WorkingSetRules HKCU\Software\Microsoft\Windows Search\Gather\Windows\SystemIndex\Protocols\Mapi HKLM\SOFTWARE\Microsoft\Windows Search\Gather\Windows\SystemIndex\Sites\ 和其他键...
  2. Windows Search 3.X 接口,例如使用 Microsoft.Search.Interop
  3. Microsoft.Office.Interop.Outlook 的 ISearchManager 类:NameSpace、Store
  4. AD 策略(无用,无效:(

首选技术:VB.NET、C#。 该解决方案必须部署在大型组织(大约 5000 个工作站)内。

有什么想法吗? 提前致谢。

After several days and multiple attempts I didn't find any 100% solution for this trouble.
My search and investigation scopes:

  1. Direct access to registry:
    HKLM\SOFTWARE\Microsoft\Windows Search\CrawlScopeManager\Windows\SystemIndex\WorkingSetRules
    HKCU\Software\Microsoft\Windows Search\Gather\Windows\SystemIndex\Protocols\Mapi
    HKLM\SOFTWARE\Microsoft\Windows Search\Gather\Windows\SystemIndex\Sites\
    and other keys...
  2. Windows Search 3.X interfaces like ISearchManager using Microsoft.Search.Interop
  3. Microsoft.Office.Interop.Outlook classes: NameSpace, Store
  4. AD policies (useless, no effect :(

Preferred technologies: VB.NET, C#.
This solution must be deployed within a large organization (about 5000 wokstations).

Any ideas?
Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鯉魚旗 2024-09-04 21:19:48
using Microsoft.Search.Interop;
using Microsoft.Office.Interop.Outlook;
using Microsoft.Win32;
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Security.Principal;

namespace PstIndexingDisabler
{
    class Program
    {
        static void Main(string[] args)
        {
            Application objApp = null;
            ISearchManager objManager = null;
            ISearchCatalogManager objCatalog = null;
            ISearchCrawlScopeManager objScope = null;
            string strSID = null;
            try
            {
                Console.WriteLine("Creating search management objects...");
                objManager = new CSearchManagerClass();
                objCatalog = objManager.GetCatalog("SystemIndex");
                objScope = objCatalog.GetCrawlScopeManager();
                Console.WriteLine("Obtaining currently logged user's SID...");
                strSID = String.Concat("{", WindowsIdentity.GetCurrent().User.Value.ToString().ToLower(), "}");
                Console.WriteLine("  The SID is: {0}", strSID);
                Console.WriteLine("Starting Outlook application...");
                objApp = new Application();
                Console.WriteLine("Enumerating PST files...");
                foreach (Store objStore in objApp.GetNamespace("MAPI").Stores)
                {
                    Console.WriteLine("Analysing file: {0}...", objStore.FilePath);
                    if (objStore.ExchangeStoreType != OlExchangeStoreType.olNotExchange || objStore.IsCachedExchange != true)
                        Console.WriteLine("  Rejected. This file is not cached exchange store.");
                    else if (Path.GetPathRoot(objStore.FilePath).StartsWith("C", StringComparison.OrdinalIgnoreCase))
                        Console.WriteLine("  Rejected. This file is located on the C: drive.");
                    else if (objStore.IsInstantSearchEnabled != true)
                        Console.WriteLine("  Rejected. Instant search was already disabled for this file.");
                    else
                    {
                        Console.WriteLine("  Accepted. Indexing of this file will be disabled.");
                        Console.WriteLine("    Computing store hash...");
                        string strHash = ComputeHash(objStore.StoreID);
                        Console.WriteLine("      The hash is: {0}.", strHash);
                        string strUrl = String.Format("mapi://{0}/{1}(${2})/", strSID, objStore.DisplayName, strHash);
                        Console.WriteLine("    Disabling indexing...");
                        Console.WriteLine("      The rule url is: {0}.", strUrl);
                        objScope.AddUserScopeRule(strUrl, 0, 1, 0);
                        objScope.SaveAll();
                        Console.WriteLine("    Operation successfull!");
                    }
                }
            }
            catch (System.Exception e)
            {
                Console.WriteLine();
                Console.WriteLine("An error occured!");
                Console.WriteLine(e.ToString());
            }
            Console.WriteLine();
            Console.WriteLine("Press return to exit.");
            Console.ReadLine();
        }
        private static string ComputeHash(string storeEID)
        {
            int idx = 0;    // Index in buffer
            uint hash = 0;    // The hash
            int lengthStoreEID = storeEID.Length / 2; // Length of store EID -- divide by 2 because 2 text characters here represents 1 byte
            // --- Pass 1: Main block (multiple of dword, i.e. 4 bytes) ---
            int cdw = lengthStoreEID / sizeof(uint);    // cdw = Count Double Words (i.e. number of double words in the buffer)
            for (int i = 0; i < cdw; i++, idx += 8)
            {
                int dword = int.Parse(storeEID.Substring(idx, 8), System.Globalization.NumberStyles.HexNumber);
                hash = (hash << 5) + hash + (uint)IPAddress.HostToNetworkOrder(dword);
            }
            // --- Pass 2: Remainder of the block ---
            int cb = lengthStoreEID % sizeof(uint);    // cb = Count Bytes (i.e. number of bytes left in the buffer after pass 1)
            for (int j = 0; j < cb; idx++, j++)
            {
                hash = (hash << 5) + hash + byte.Parse(storeEID.Substring(idx, 2), System.Globalization.NumberStyles.HexNumber);
            }
            return hash.ToString("x");
        }
        private static string EncodeEID(string EID)
        {
            StringBuilder result = new StringBuilder(EID.Length);
            for (int i = 0; i < EID.Length; i += 2)
                result.Append((char)(byte.Parse(EID.Substring(i, 2), System.Globalization.NumberStyles.HexNumber) + 0xAC00));
            return result.ToString();
        }
    }
}
using Microsoft.Search.Interop;
using Microsoft.Office.Interop.Outlook;
using Microsoft.Win32;
using System;
using System.IO;
using System.Text;
using System.Net;
using System.Security.Principal;

namespace PstIndexingDisabler
{
    class Program
    {
        static void Main(string[] args)
        {
            Application objApp = null;
            ISearchManager objManager = null;
            ISearchCatalogManager objCatalog = null;
            ISearchCrawlScopeManager objScope = null;
            string strSID = null;
            try
            {
                Console.WriteLine("Creating search management objects...");
                objManager = new CSearchManagerClass();
                objCatalog = objManager.GetCatalog("SystemIndex");
                objScope = objCatalog.GetCrawlScopeManager();
                Console.WriteLine("Obtaining currently logged user's SID...");
                strSID = String.Concat("{", WindowsIdentity.GetCurrent().User.Value.ToString().ToLower(), "}");
                Console.WriteLine("  The SID is: {0}", strSID);
                Console.WriteLine("Starting Outlook application...");
                objApp = new Application();
                Console.WriteLine("Enumerating PST files...");
                foreach (Store objStore in objApp.GetNamespace("MAPI").Stores)
                {
                    Console.WriteLine("Analysing file: {0}...", objStore.FilePath);
                    if (objStore.ExchangeStoreType != OlExchangeStoreType.olNotExchange || objStore.IsCachedExchange != true)
                        Console.WriteLine("  Rejected. This file is not cached exchange store.");
                    else if (Path.GetPathRoot(objStore.FilePath).StartsWith("C", StringComparison.OrdinalIgnoreCase))
                        Console.WriteLine("  Rejected. This file is located on the C: drive.");
                    else if (objStore.IsInstantSearchEnabled != true)
                        Console.WriteLine("  Rejected. Instant search was already disabled for this file.");
                    else
                    {
                        Console.WriteLine("  Accepted. Indexing of this file will be disabled.");
                        Console.WriteLine("    Computing store hash...");
                        string strHash = ComputeHash(objStore.StoreID);
                        Console.WriteLine("      The hash is: {0}.", strHash);
                        string strUrl = String.Format("mapi://{0}/{1}(${2})/", strSID, objStore.DisplayName, strHash);
                        Console.WriteLine("    Disabling indexing...");
                        Console.WriteLine("      The rule url is: {0}.", strUrl);
                        objScope.AddUserScopeRule(strUrl, 0, 1, 0);
                        objScope.SaveAll();
                        Console.WriteLine("    Operation successfull!");
                    }
                }
            }
            catch (System.Exception e)
            {
                Console.WriteLine();
                Console.WriteLine("An error occured!");
                Console.WriteLine(e.ToString());
            }
            Console.WriteLine();
            Console.WriteLine("Press return to exit.");
            Console.ReadLine();
        }
        private static string ComputeHash(string storeEID)
        {
            int idx = 0;    // Index in buffer
            uint hash = 0;    // The hash
            int lengthStoreEID = storeEID.Length / 2; // Length of store EID -- divide by 2 because 2 text characters here represents 1 byte
            // --- Pass 1: Main block (multiple of dword, i.e. 4 bytes) ---
            int cdw = lengthStoreEID / sizeof(uint);    // cdw = Count Double Words (i.e. number of double words in the buffer)
            for (int i = 0; i < cdw; i++, idx += 8)
            {
                int dword = int.Parse(storeEID.Substring(idx, 8), System.Globalization.NumberStyles.HexNumber);
                hash = (hash << 5) + hash + (uint)IPAddress.HostToNetworkOrder(dword);
            }
            // --- Pass 2: Remainder of the block ---
            int cb = lengthStoreEID % sizeof(uint);    // cb = Count Bytes (i.e. number of bytes left in the buffer after pass 1)
            for (int j = 0; j < cb; idx++, j++)
            {
                hash = (hash << 5) + hash + byte.Parse(storeEID.Substring(idx, 2), System.Globalization.NumberStyles.HexNumber);
            }
            return hash.ToString("x");
        }
        private static string EncodeEID(string EID)
        {
            StringBuilder result = new StringBuilder(EID.Length);
            for (int i = 0; i < EID.Length; i += 2)
                result.Append((char)(byte.Parse(EID.Substring(i, 2), System.Globalization.NumberStyles.HexNumber) + 0xAC00));
            return result.ToString();
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文