Machine filters are the only type of persistent filters currently supported by the SMS API. The steps to create a persistent filter are the same as the steps for creating a transient machine filter, with addition of two steps to:
 To create a persistent filter
    To create a persistent filterThe SmsCreateFilter function takes three parameters:
Example:
// Create a machine filter to stored as 
// a persistent filter, that is, a query.
HANDLE hNewFilter;
stat = SmsCreateFilter( MACHINE_FILTER, // Machine filter.
                        hConnect,   // Handle to database
                                    // connection.
                        &hNewFilter // Assign handle to new filter
                      );            // to hNewFilter.
To add a token to a filter, use the SmsAddToken function.
The SmsAddToken function takes four parameters:
Example:
// Add a token to the machine filter that
// finds all computers with a 486 processor.
TOKEN Token;
// Clear the Token structure.
memset( &Token, 0, sizeof (TOKEN) );
// Set the expression token to 
// "Attribute Processor Name from group MICROSOFT|PROCESSOR|1.0 
// contains 486 (ie, Processor Name is like %486%)".
// Set the architecture, groupclass, and attribute.
strcpy( Token.szArchitecture, "Personal Computer");
strcpy( Token.szGroupClass, "MICROSOFT|PROCESSOR|1.0");
strcpy( Token.szAttributeName, "Processor Name");
// Set the operator used to evaluate the expression.
Token.dwOp = QOP_STR_LIKE; // Use the 'is like' operator.
// Set the value to evaluate.
strcpy( Token.szValue, "%486%"); 
// Add the token to the filter.
stat = SmsAddToken( hFilter, // Specifies the handle to filter.
                    OP_AND,  // Use the AND control token to 
                             // connect the expression to 
                             // adjacent expressions.
                    &Token,  // Specifies the structure for
                              // the expression token.
                    AT_END   // Add the token to the end of 
                             // the filter.
                  );
A persistent filter has four scalars:
Name and Architecture must be set by your application before a persistent filter is added to the site database by using SmsCommitFilter.
Use the SmsSetScalar function to set the value of a scalar.
The SmsSetScalar function takes two parameters:
Example:
// Set the Name of the persistent filter (query).
SCALAR sc;                  // Declare SCALAR struct to hold 
                            // scalar data.
char *szScalarName = "Name"; // Name of the scalar to set.
SCALARTYPE scType = SCALAR_STRING; // Data type of scalar.
char *pszScalarValue = "Find all 486s"; // Value to set.
// Assign the scalar data to the sc structure.
sc.pszName = szScalarName;
sc.scType  = scType;
sc.dwLen = sizeof(pszScalarValue)-1;
sc.pszValue = pszScalarValue;
// Use SmsSetScalar to use the sc struct to 
// set the scalar for the filter.
stat = SmsSetScalar( hFilter,   // Handle to filter containing 
                                 // the scalar to set.
                     &sc         // Pointer to SCALAR struct 
                                 // containing value to set.
                   );
The SmsCommitFilter function takes two parameters:
Example:
// Write the machine filter to the site database.
stat = SmsCommitFilter( hFilter,     // Handle to filter.
                        hFContainer  // Handle to filter 
                                     // container.
                      );
Note that the new machine filter is not written to the site database until the application calls the SmsCommitFilter function for that filter.