Exclude directories from Windows Search by wildcard

I looked in the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Search\CrawlScopeManager\Windows\SystemIndex\DefaultRules key and found something interesting.

DefaultRules\1 contains:

Default   REG_DWORD    0x00000001
Include   REG_DWORD    0x00000000
Policy    REG_DWORD    0x00000000
Suppress  REG_DWORD    0x00000000
URL       REG_SZ       file:///C:\Users\*\AppData\Local\Temp\*

Look at that URL key - two wildcards!

So since Windows Search natively supports wildcards, all we have to do is tweak an existing exception.

Adding wildcard exceptions to Windows Search

  1. Add template exception.
    Add an exception for a suitable directory by going to Indexing OptionsModify and deselecting one directory (in my case, C:\Users\MyName\dev\trunk\bin).
  2. Stop the Windows Search service.
    Go to Services, select Windows Search, right-click on it, and select Stop.
  3. Find the existing exception.
    Open Registry Editor and navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Search\CrawlScopeManager\Windows\SystemIndex\WorkingSetRules.
    Look through each numbered subkey to find yours.
  4. Tweak the exception.
    In my case, I have multiple branches checked out, so I will have directories for trunk and for each versioned branch (such as 3.2, 4.0, etc). So I changed the URL key from

    file:///C:\Users\MyName\dev\ProjectName\trunk\bin
    

    to

    file:///C:\Users\MyName\dev\ProjectName\*\bin
    
  5. Restart the Windows Search service.
    Right-click on Windows Search and select Start or Restart.

That's it! The directories are even unchecked/excluded in the Indexing Options.