IT:Searching the contents of files

From Stiki

Jump to: navigation, search

Using the Windows Search Companion one of the criteria for finding target files is to limit the search by "A word or phrase in the file". This can be a very useful piece of functionality. However although the option appears for whatever type of file you search for, it may not necessarily produce any results if the file type has not been set up as required.

There is a key in the registry called PersistentHandler that is used for searching the contents of files. From the root of the registry if you look in HKEY_CLASSES_ROOT you will see a list of all file extensions that your operating system recognises. The text file extension ".txt" should have a PersistentHandler key with a value of {5e941d80-bf96-11cd-b579-08002b30bfeb}.

In order to allow file content searching for file types that have not been set up yet, you will need to create and populate the PersistentHandler key for the corresponding file extension. You should do this by copying the key from an existing file type that does work.

Example file formats that are stored as text

For example the following extensions are all purely text files and so can use the same search algorithm for file content:

  • Text files:
    • .CSV (comma-separated values)
    • .RTF (rich text format)
    • .TXT (plain text files)
  • Web page files:
    • .CSS (cascading style sheets)
    • .HTM and .HTML (hyper text markup language documents)
    • .PHP (PHP file)
    • .XML (extensible markup language documents)
  • Microsoft Visual Studio files:
    • .MYAPP (Visual Studio my application data)
    • .SETTINGS (Visual Studio settings-designer file)
    • .SLN (Visual Studio solution)
    • .VB (Visual Basic source file)
    • .VBPROJ (Visual Basic project file)
    • .VSSETTINGS (Visual Studio settings file)
  • Microsoft Visual Basic and VBA files:
    • .BAS (modules)
    • .FRM (forms)
  • Prophet files:
    • .FAC (tables)
    • .PRO (modelpoint files)
    • .RPT (results files)
  • Assorted other files:
    • .BAT (DOS batch files)
    • .INI (Windows configuration settings)
    • .JS (JavaScript script files)
    • .REG (Windows registry patches)
    • .SQL (structured query language files)

(This is not intended to be an exhaustive list, but should give you an idea of how widespread pure text files are amongst the various file types.)

How to change the registry

IMPORTANT WARNING: The registry is an integral part of Microsoft Windows and changing its contents can potentially permanently disable your operating system installation. Always make a back-up of the registry before changing it. And if you're not sure of what you're doing, don't change the registry!

The safest method is to take a copy the existing key for a file type that already works, and alter it to meet your needs. For example, consider the task to allow text file content searching for various Prophet files (with extensions .FAC, .PRO, .RPT):

  1. Open the registry. You do this through an application called Registry Editor. The application file is REGEDIT.EXE which is found in the Windows directory (usually this is at 'C:\Windows'). Alternatively you can run the application directly from the Run dialog (from the Start menu select Run, or press Windows+R, then type "regedit" in the text box).
  2. Check that there isn't already a PersistentHandler key for any of the desired file extensions. Do this by browsing through the registry tree to HKEY_CLASSES_ROOT (from the root of the registry) and then to each of the file extensions in turn.
  3. Browse to the ".txt" file extension and select the key called "PersistentHandler". Right-click on this key and select "Export". Enter an appropriate file name to save this key as a registry patch.
  4. Open the saved registry patch using Notepad or some other text editor. Do this either by opening the text editor application and then opening the registry patch from within it, or by right-clicking on the registry patch and selecting "Edit". (Note that the default action of directly opening the registry patch by double-clicking on it is to add the patch to the registry, rather than to edit its contents.) You should see something like this:
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\.txt\PersistentHandler]
@="{5e941d80-bf96-11cd-b579-08002b30bfeb}"
  1. Edit this to allow for the file extensions that you wish to update. For example for the Prophet files:
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\.fac\PersistentHandler]
@="{5e941d80-bf96-11cd-b579-08002b30bfeb}"

[HKEY_CLASSES_ROOT\.pro\PersistentHandler]
@="{5e941d80-bf96-11cd-b579-08002b30bfeb}"

[HKEY_CLASSES_ROOT\.rpt\PersistentHandler]
@="{5e941d80-bf96-11cd-b579-08002b30bfeb}"
  1. Save this change and exit the text editor. Now you can add this patch to the registry by double-clicking on it. Windows will always prompt you to confirm adding any patch, because of the dangers of damaging the registry.

This should now enable to you use the Windows Search Companion to search the contents of these file types.

Personal tools