以编程方式搜索 Windows 7,无需使用 sdk 库

发布于 2024-12-23 05:33:16 字数 192 浏览 2 评论 0原文

有没有办法用参数调用 SearchIndexer ? (或者还有其他方法可以实现标题所说的功能吗?)

我尝试查看各种 MSDN 文章,但它们似乎都建议我使用库。但是当我运行搜索时,它就会运行,而无需我下载任何类型的库。

回到 XP 时代,您可以转到索引服务属性并执行查询。我在 Windows 7 中看不到这一点。

谢谢。

Is there a way to call SearchIndexer with arguments? (or is there another way to accomplish what the title says?)

I tried looking at the various MSDN articles, but they all seemed to suggest that I use a library. But when I run the search, it runs, without me downloading any sort of library.

Back in the days of XP, you could go to the indexing service properties and execute a query. I don't see that in Windows 7.

Thanks.

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

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

发布评论

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

评论(1

情场扛把子 2024-12-30 05:33:16

这是一个示例查询。请注意,它不使用 Windows 7 SDK。

using System;
using System.Data.OleDb;

namespace FileSearchingExe
{
class MainProgram
{
    static void Main(string[] args)
    {     
string sqlQuery = "SELECT TOP 10 \"System.ItemPathDisplay\", \"System.DateModified\" FROM \"SystemIndex\" WHERE CONTAINS(*,'\"urSearchWord*\"') " +
            "AND scope='file:C:/SomeFolder' ORDER BY System.ItemPathDisplay DESC"; //note the forwardslash in the scope parameter.

        // --- Perform the query ---
        // create an OleDbConnection object which connects to the indexer provider with the windows application
        using (System.Data.OleDb.OleDbConnection conn = new OleDbConnection("provider=Search.CollatorDSO.1;EXTENDED PROPERTIES=\"Application=Windows\""))//queryHelper.ConnectionString))
        {
            // open the connection
            conn.Open();

            // now create an OleDB command object with the query we built above and the connection we just opened.
            using (OleDbCommand command = new OleDbCommand(sqlQuery, conn))
            {
                // execute the command, which returns the results as an OleDbDataReader.
                using (OleDbDataReader WDSResults = command.ExecuteReader())
                {
                    while (WDSResults.Read())
                    {
                        // col 0 is our path in display format

                        Console.WriteLine("{0}, {1}", WDSResults.GetString(0), WDSResults.GetDateTime(1).ToString());
                    }
                }
            }
        }
     }
 }
 }

但是,它是根据 Windows 7 SDK 中的 DSearch 示例改编的。 ([SDK]\Samples\winui\WindowsSearch\DSearch。[SDK]通常是“C:\Program Files\Microsoft SDKs\Windows\v7.1”

请注意,您可以使SQL查询更容易(但在我看来稍微不太灵活) )如果您使用 SDK 的 ISearchQueryHelper,但要使用该类和相关类,您需要引用 Microsoft.Search.Interop,该类未包含在 Windows 7 中。 SDK为但是,您可以通过在 SearchAPI.tlb 文件(在 [SDK]\Lib 中)上使用 TlbImp.exe(类型库导入程序,在 [SDK]\bin 中)以 dll 形式获取它。 href="http://social.msdn.microsoft.com/Forums/en-US/windowssearch/thread/0a130e9d-4710-4a72-bf9e-272a3f0128d6/" rel="nofollow">此处也有描述。

我希望这篇文章对需要以编程方式连接到 Windows 7 或更高版本中的 Windows 搜索的其他人有所帮助。

Here's an example query. Note that it does not use the Windows 7 SDK.

using System;
using System.Data.OleDb;

namespace FileSearchingExe
{
class MainProgram
{
    static void Main(string[] args)
    {     
string sqlQuery = "SELECT TOP 10 \"System.ItemPathDisplay\", \"System.DateModified\" FROM \"SystemIndex\" WHERE CONTAINS(*,'\"urSearchWord*\"') " +
            "AND scope='file:C:/SomeFolder' ORDER BY System.ItemPathDisplay DESC"; //note the forwardslash in the scope parameter.

        // --- Perform the query ---
        // create an OleDbConnection object which connects to the indexer provider with the windows application
        using (System.Data.OleDb.OleDbConnection conn = new OleDbConnection("provider=Search.CollatorDSO.1;EXTENDED PROPERTIES=\"Application=Windows\""))//queryHelper.ConnectionString))
        {
            // open the connection
            conn.Open();

            // now create an OleDB command object with the query we built above and the connection we just opened.
            using (OleDbCommand command = new OleDbCommand(sqlQuery, conn))
            {
                // execute the command, which returns the results as an OleDbDataReader.
                using (OleDbDataReader WDSResults = command.ExecuteReader())
                {
                    while (WDSResults.Read())
                    {
                        // col 0 is our path in display format

                        Console.WriteLine("{0}, {1}", WDSResults.GetString(0), WDSResults.GetDateTime(1).ToString());
                    }
                }
            }
        }
     }
 }
 }

However, it was adapted from the DSearch example in the Windows 7 SDK. ([SDK]\Samples\winui\WindowsSearch\DSearch. [SDK] is typically "C:\Program Files\Microsoft SDKs\Windows\v7.1"

Note that you can make the SQL query more easily (but slightly less flexible imo) if you use the SDK's ISearchQueryHelper. To use that class and related classes though, you need have reference to Microsoft.Search.Interop, which is not included in the Windows 7 SDK as a dll. You can however get it in dll form by using TlbImp.exe (type library importer, in [SDK]\bin) on the SearchAPI.tlb file (in [SDK]\Lib). Also described here.

I hope this post helps anyone else who needs to programmatically connect to the Windows Search in Windows 7 or higher.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文