次の方法で共有


ChgState Sample

Note

Indexing Service is no longer supported as of Windows XP and is unavailable for use as of Windows 8. Instead, use Windows Search for client side search and Microsoft Search Server Express for server side search.

 

The ChgState example is a command-line application written in C++ that can either report the current state of a catalog or change the state of the catalog using the SetCatalogState function of the OLE DB Helper API.

Source: mssdk\samples\winbase\indexing\ChgState\

To build the sample

  1. Set the Lib environment variable to "D:\mssdk\Lib;%Lib%" and the Include environment variable to "D:\mssdk\Include;%Include%", where D: is the drive on which you installed the Platform SDK.
  2. Correctly set the CPU environment variable to, for example, "i386".
  3. Open a command window and change the directory to the source path of the sample.
  4. Build the sample by entering, at the command-line prompt, "nmake".

To find or change the catalog state using the sample

  1. Open a command window and change the directory to the path of the built sample.

  2. Submit a catalog state command by entering, at the command-line prompt, chgstate /a:<action> [/c:<catalog>] [/m:<machine>]

    where the values of the command-line parameters are the following.

    Value Meaning
    <action>
    is a catalog state action; one of the following:
    RO sets read-only (queries only)
    RW sets read/write (queries and indexing)
    Stop sets stopped (no queries or indexing)
    GetState gets current state only
    <catalog>
    is the name of the catalog (default is "system")
    <machine>
    is the name of the machine (default is ".")

     

Programming Notes

The previous state of the specified catalog is always returned in the dwOldState parameter of the SetCatalogState function and printed by the sample.

The state of the catalog will change to the new, specified state if that state does not violate read-only rules for the catalog. If the catalog resides on a read-only medium, the catalog is specified as read-only in the registry, or if the file cicat.hsh is set to read-only, the catalog is set to read-only even when the read/write state is requested.

Parameters

The <action> parameter is the action desired. Four actions are possible:

  • RO (Read-only): Queries are allowed, but no indexing occurs.
  • RW (Read/write): Queries are allowed and indexing occurs.
  • Stop (Stopped): Stops catalog completely (no queries, no indexing).
  • GetState (Get state): Gets the current state of a catalog only. The catalog state prior to any specified action is always returned.

The <catalog> parameter is the name of the catalog on which to perform the action. The default value of the <catalog> parameter is "system", which is the default catalog installed. Additional catalogs can be created with the Indexing Service snap-in of the Microsoft Management Console (MMC).

The <machine> parameter is the name of the computer on which the request is executed. The default is ".", which is the local computer. Computer names should not be preceded by two backslashes.

Examples

Change the "system" catalog on the local computer to the Read/write state.

chgstate /a:RW /c:system

Get the current state of the "system" catalog on machine SERVERNAME.

chgstate /a:GetState /m:SERVERNAME

Set the catalog CATALOGNAME on machine SERVERNAME to the Read-only state. (The catalog can be queried, but indexing is stopped.)

chgstate /a:RO /c:CATALOGNAME /m:SERVERNAME