Calling Windows Search programatically in Windows 7


  • Hi,

    I have a software application which has a facility to automatically call Windows Desktop Search and pass a search parameter to it. This works fine on XP machines which have WDS installed

    For example, you just run this command and WDS will search for every file associated with 'ref123':
    "C:\Program Files\Windows Desktop Search\WindowsSearch.exe" /url "search-ms://query=ref123"

    Now how can I do something similar in Windows 7?

    Since Windows Search is not a component part of the OS, it is not longer installed in C:\Program Files and instead now consists of 3 different exes which are located in the System32 folder:

    Anyone know how this can be done?


    Friday, December 04, 2009 10:55 AM

All replies

  • Actually I am wrong in that SearchIndexer.exe, SearchProtocolHost.exe and SearchFilterHost.exe were also present in XP

    So my problem is basically how do I call WindowsSearch.exe programatically in Windows 7 when it does not exist? Where can I find the built-in Windows 7 search application?
    Friday, December 04, 2009 4:32 PM
  • Just run:
    explorer.exe "search-ms://query=ref123"
    • Proposed as answer by Andrei Aron MS Friday, December 04, 2009 6:22 PM
    Friday, December 04, 2009 6:22 PM
  • Thank you !
    Monday, December 07, 2009 9:20 AM
  • Uhm, I just got wery happy!
    But then i realized that this approach just shows a new "explorer" window with the result set.  Is it possible to get a hold of this result by code?

    Like some kind of a LINQ request perhaps?

    Monday, December 07, 2009 7:08 PM
  • Sure,
    We expose searching capabilities in several different layers. The most relevant two are:

    OLE-DB: (queries the indexer directly, gives you the results in the form of a Rowset)

    Shell Data Model (this is significantly more involved, but you can generate the same UI that Explorer uses)
    see the Samples/Shell/SearchApplication for a custom search implementation.

    Hope this helps,
    Monday, December 07, 2009 7:15 PM
  • Hi and thanx

    I have tryed that example code but it fails with an exception.  I tryed one of the examples:

    c:\Data\Work\Visual Studio\Windows Search\Querying\WSSQL\bin\Debug>wssql select
    top 10 "system.itempathdisplay" from "systemindex" where scope = "file:"

    Got OleDbException, error code is 0x80040E14L
    Exception details:
            Error 0
                    Message: En eller flere feil oppstod under behandling av kommando.
                    Native: 0
                    Source: IErrorInfo.GetSource mislyktes med E_FAIL(0x80004005).

            Error 1
                    Message: IErrorInfo.GetDescription mislyktes med E_FAIL(0x80004005).
                    Native: 0
                    Source: IErrorInfo.GetSource mislyktes med E_FAIL(0x80004005).

    System.Data.OleDb.OleDbException: En eller flere feil oppstod under behandling a
    v kommando.
    IErrorInfo.GetDescription mislyktes med E_FAIL(0x80004005).
       ved System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResu
    lt hr)
       ved System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPAR
    AMS dbParams, Object& executeResult)
       ved System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
       ved System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior beha
    vior, String method)
       ved System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior)
       ved Microsoft.WindowsSDK.WSSQL.Program.ExecuteQuery(String query, Int32 chapt
    erDepth) i c:\Data\Work\Visual Studio\Windows Search\Querying\WSSQL\WSSQL.cs:lin
    je 120

    Pleas help.

    Tuesday, December 08, 2009 10:02 AM
  • Just run:
    WSSQL.exe "select system.itempathdisplay from systemindex where scope = 'file:C:/'"

    You have to surround the query with double quotes.
    Tuesday, December 08, 2009 9:34 PM