Programmaticaly防止Vista桌面搜索(WDS)从索引放置在映射网络驱动器的PST文件 [英] Programmaticaly prevent Vista desktop search (WDS) from indexing pst files placed on mapped network drives
本文介绍了Programmaticaly防止Vista桌面搜索(WDS)从索引放置在映射网络驱动器的PST文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在几天多次尝试我没有找到这个麻烦任何100%的解决方案。
我的搜索和调查范围:
- 直接访问注册表:
HKLM\SOFTWARE\Microsoft\窗户Search\CrawlScopeManager\Windows\SystemIndex\WorkingSetRules
HKCU\Software\Microsoft\Windows Search\Gather\Windows\SystemIndex\Protocols\Mapi
HKLM\\ \\SOFTWARE\Microsoft\Windows Search\Gather\Windows\SystemIndex\Sites\
和其他键... - Windows搜索3.X界面像ISearchManager使用Microsoft.Search.Interop
- Microsoft.Office.Interop.Outlook类:名字空间,存储
- 广告政策(无用的,没有效果: (
首选技术:VB.NET,C#
该解决方案必须在大型组织(约5000 wokstations内部署。 )。
任何想法?
先谢谢了。
解决方案
使用Microsoft.Search.Interop;
使用的Microsoft.Win32;使用系统
使用Microsoft.Office.Interop.Outlook
;
:使用System.IO;
使用System.Text;使用System.Net
;
使用System.Security.Principal;
命名空间PstIndexingDisabler
{
类节目
{
静态无效的主要(字串[] args)
{
应用objApp = NULL;
ISearchManager objManager = NULL;
ISearchCatalogManager objCatalog = NULL;
ISearchCrawlScopeManager objScope = NULL;
字符串strSID = NULL;
试
{
Console.WriteLine(创建搜索管理对象...);
objManager =新CSearchManagerClass();
objCatalog = objManager.GetCatalog(SystemIndex);
objScope = objCatalog.GetCrawlScopeManager();
Console.WriteLine(获取当前登录用户的SID ...);
strSID = String.Concat({。,WindowsIdentity.GetCurrent()User.Value.ToString()ToLower将(),});
Console.WriteLine(SID是:{0},strSID);
Console.WriteLine(启动Outlook应用程序...);
objApp =新的应用程序();
Console.WriteLine(枚举PST文件......);
的foreach(存储在objStore objApp.GetNamespace(MAPI)存储。)
{
Console.WriteLine(试析文件:{0} ...,objStore.FilePath);
如果(objStore.ExchangeStoreType = OlExchangeStoreType.olNotExchange || objStore.IsCachedExchange =真!)
Console.WriteLine(拒绝了这个文件不被缓存Exchange存储。);
,否则如果(Path.GetPathRoot(objStore.FilePath).StartsWith(C,StringComparison.OrdinalIgnoreCase))
Console.WriteLine(拒绝了这个文件位于C:驱动器) ;
,否则如果(objStore.IsInstantSearchEnabled =真!)
Console.WriteLine(被拒绝的即时搜索已经为这个文件无效。);
,否则
{
Console.WriteLine(。该文件的索引接受将被禁用。);
Console.WriteLine(计算哈希存储...);
串strHash = ComputeHash(objStore.StoreID);
Console.WriteLine(哈希为:{0},strHash);
串strUrl =的String.Format(MAPI:// {0} / {1}($ {2})/,strSID,objStore.DisplayName,strHash);
Console.WriteLine(禁用索引...);
Console.WriteLine(规则网址为:{0},strUrl);
objScope.AddUserScopeRule(strUrl,0,1,0);
objScope.SaveAll();
Console.WriteLine(操作全成!);
}
}
}
赶上(System.Exception的E)
{
Console.WriteLine();
Console.WriteLine(发生错误!);
Console.WriteLine(e.ToString());
}
Console.WriteLine();
Console.WriteLine(按回车键退出。);
到Console.ReadLine();
}
私人静态字符串ComputeHash(字符串storeEID)
{
INT IDX = 0; //指数缓冲器
UINT散列= 0; //散列
INT lengthStoreEID = storeEID.Length / 2;店内开斋节//长度 - 这里由2,因为2文本字符鸿沟代表1个字节
// ---通1:主程序(DWORD多,也就是4个字节)---
INT CDW = lengthStoreEID /的sizeof(UINT); // CDW =计数双字(在缓冲区中的双字,即数)
的for(int i = 0; I< CDW;我++,IDX + = 8)
{
INT DWORD = int.Parse(storeEID.Substring(IDX,8),System.Globalization.NumberStyles.HexNumber);
哈希=(散列<< 5)+散+(UINT)IPAddress.HostToNetworkOrder(DWORD);
}
// ---通2:该块---
INT CB = lengthStoreEID%的sizeof(UINT)的剩余部分; // CB = count字节(即留在缓冲区后传1字节数)
为(INT J = 0; J< CB; IDX ++,J ++)
{
哈希= (散列&所述;小于5)+散列+ byte.Parse(storeEID.Substring(IDX,2),System.Globalization.NumberStyles.HexNumber);
}
返回hash.ToString(×);
}
私人静态字符串EncodeEID(字符串EID)
{
StringBuilder的结果=新的StringBuilder(EID.Length);
的for(int i = 0; I< EID.Length;我+ = 2)
result.Append((炭)(byte.Parse(EID.Substring(1,2),系统。 Globalization.NumberStyles.HexNumber)+ 0xAC00));
返回result.ToString();
}
}
}
After several days and multiple attempts I didn't find any 100% solution for this trouble. My search and investigation scopes:
- 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...
- Windows Search 3.X interfaces like ISearchManager using Microsoft.Search.Interop
- Microsoft.Office.Interop.Outlook classes: NameSpace, Store
- 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.
解决方案
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();
}
}
}
这篇关于Programmaticaly防止Vista桌面搜索(WDS)从索引放置在映射网络驱动器的PST文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文