【问题标题】:How to add a location to windows 7/8 search index using batch or vbscript?如何使用批处理或 vbscript 将位置添加到 Windows 7/8 搜索索引?
【发布时间】:2012-11-03 15:20:29
【问题描述】:

我正在尝试以编程方式将位置(范围)添加到我的 Windows 8 搜索索引中,经过一番谷歌搜索后,我找到了 this 代码:

Set objISAdm = CreateObject("Microsoft.ISAdm")
Set objCatalog = objISAdm. GetCatalogByName("MyCatatlog")
Set objScope= objCatalog.AddScope("C:\myfiles",False)
objScope.Alias = "MyCatalogScope"

很遗憾,出现800A01AD错误提示提示对象Microsoft.ISAdm无法创建;经过进一步挖掘,上面的代码似乎不适用于 Windows 8 上较新版本的 Windows Search。

有谁知道如何使用 VB 脚本或从命令行执行此操作,大概在 Windows 7 下工作的东西也可以在 Windows 8 上工作?

【问题讨论】:

    标签: powershell vbscript windows-search


    【解决方案1】:

    加雷特,你真是个天才!这是我从您提供的链接中学到的代码:

    #Code copied from "Powershell Tackles Windows Desktop Search" http://powertoe.wordpress.com/2010/05/17/powershell-tackles-windows-desktop-search/
    #Microsoft.Search.Interop.dll is needed, download from http://www.microsoft.com/en-us/download/details.aspx?id=7388
    #Load the dll
    Add-Type -path "D:\Unattend\UserFiles\Tools\Microsoft.Search.Interop.dll"
    #Create an instance of CSearchManagerClass
    $sm = New-Object Microsoft.Search.Interop.CSearchManagerClass 
    #Next we connect to the SystemIndex catalog
    $catalog = $sm.GetCatalog("SystemIndex")
    #Get the interface to the scope rule manager
    $crawlman = $catalog.GetCrawlScopeManager()
    #add scope
    $crawlman.AddUserScopeRule("file:///D:\*",$true,$false,$null)
    $crawlman.SaveAll()
    

    将代码另存为 AddScope.ps1,然后从提升的 cmd 控制台运行它:

    PowerShell Set-ExecutionPolicy Unrestricted -force
    PowerShell D:\Unattend\UserFiles\AddScope.ps1
    

    就是这样!

    【讨论】:

    • 您可以在不更改执行策略的情况下运行它:powershell -executionpolicy unrestricted d:\unattend\userfiles\addscope.ps1 执行策略的目的是不在不知不觉中执行脚本。
    【解决方案2】:

    在您提供的代码中,您尝试使用Indexing service interface。 Windows 8 中不再提供索引服务。从文档中:

    从 Windows XP 开始不再支持索引服务,而是 自 Windows 8 起无法使用。相反,请使用 Windows Search for 用于服务器端的客户端搜索和 Microsoft Search Server Express 搜索。

    如文档所述,您需要查看Windows Search

    更新:

    我没有这样做,但要完成您正在寻找的 documentation 状态

    在您可以使用任何 Crawl Scope Manager (CSM) 界面之前, 您必须执行以下先决步骤:

    1. 创建 CrawlSearchManager 对象并获取其 ISearchManager 接口。
    2. 为“SystemIndex”调用 ISearchManager::GetCatalog 以获取 ISearchCatalogManager 接口的实例。
    3. 调用 ISearchCatalogManager::GetCrawlScopeManager 获取 ISearchCrawlScopeManager 接口的实例。

    对抓取范围管理器 (CSM) 进行任何更改后,您必须 调用 ISearchCrawlScopeManager::SaveAll。这种方法不需要 参数并在成功时返回 S_OK。

    这里有一个 exampleanother 用于执行此操作。

    不幸的是,我认为这不能通过 VBScript 完成,因为 Windows Search API 提供的 COM interfaces 没有实现 IDispatch 接口,它允许像 VBScript 这样的脚本语言通过以下方式调用 COM 对象late binding

    它必须来自 VBScript,还是可以在 .NET 中实现?如果它必须来自 VBScript,那么一种方法是在 .NET 中编写一个包装器并将expose 它作为一个 COM 对象。

    【讨论】:

    • 谢谢加雷特。您提供的信息正是我从 MSDN 中找到的。我认为使用 ISearchCrawlScopeManager::AddRoot 方法是正确的方向。但是我不是VB/VBS程序员,能给我一些工作代码吗?
    • 有人知道如何使用 ISearchCrawlScopeManager::AddRoot 方法吗?
    • 再次感谢加雷特!如果必须使用可执行二进制文件来完成,那就有点太复杂了。我之所以问,是因为我想在无人值守的 Windows 设置之后自动将位置添加到索引中。你的回答很有价值。它让我免于追鬼。
    • 还有一个问题,可以用PowerShell来完成吗?
    • @user24442 是的,它可以通过 PowerShell 完成。有关示例,请参阅 yellowonline.tweakblogs.net/blog/7285/…powertoe.wordpress.com/2010/05/17/…
    猜你喜欢
    • 2011-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-04
    相关资源
    最近更新 更多