views:

470

answers:

5

I'd like to determine how to programatically start/stop/pause the indexer from Microsoft Search.

I know it is possible because I've seen it done in programs like this one: http://brandontools.com/files/folders/sidebar%5Fgadgets/entry511.aspx

However, I cannot find any docs on MSDN or anywhere.

There is a "Windows Search" service which can be controlled with traditional service control methods. However, starting/stopping this service also changes the availability of search itself. I want to control just the indexer.

Does anyone know where docs may be found that describe how to interact with the indexer? My search skills have failed me.

A: 

Something like this:

ServiceController service = new ServiceController("WSearch");

service.Start();

or

service.Stop();

Peter Mourfield
The OP said that that stops all search availability, not just indexing...
bdonlan
+1  A: 

According the Microsoft there isn't an official way of doing so.

Shay Erlichmen
A: 

There isn't a way to simply disable the indexing part. It's an all or nothing service. The description of the WSearch service states:

"Provides content indexing and property caching for file, email and other content (via extensibility APIs). The service responds to file and email notifications to index modified content. If the service is stopped or disabled, the Explorer will not be able to display virtual folder views of items, and search in the Explorer will fall back to item-by-item slow search."

However, you might be able to control it through drive/folder properties ... from Explorer, you can switch it of for an individual drive (see the properties of a drive; there's an option "allow indexing service..."), or for a folder (folder properties -> advanced -> "For fast searching, allow indexing service...").

EDIT ... a bit of googling, and the above properties are available - if you look at the MSDN page for System.IO.FileAttributes, there's a property NotContentIndexed with the description The file will not be indexed by the operating system's content indexing service. I would assume that you should be able to set this on individual folders. I don't know if this works if set at the drive level (without a recursive run through the drive), but hopefully it'll give you a head-start on whatever you're ultimately trying to achieve.

Chris J
A: 

Open the "Run" Dialog (Start | Run), type(or copy) %SystemRoot%\system32\compmgmt.msc /s and unfold the last one

genodeftest
OP is looking for a programmatic solution, not a front-end solution.
Chris J
A: 

Here is a great tutorial on programmatically interacting with Windows Search: article at JoyOfCode.

The Windows Search 3.x SDK provides a .NET API that works against Windows Search 3 or 4.

Unfortunately, it doesn't expose pause/resume. All of the index control samples I have found use WMI to stop the search service. That will stop indexing, obviously, but at the expense of search itself not being available.

Aidan Ryan