Setting Tokens for an Inventory Rules Folder

An inventory rules folder (which can be a subfolder within a package folder) contains only one scalar. However, an inventory rules folder must also contain one or more tokens that represent the rule for collecting inventory on the package.

The inventory rules folder uses expression tokens and control tokens in the same way that filters do—except that each expression token contains a string that specifies attributes that identify the file. In addition, the NOT operator is not supported for inventory rules. For an inventory rules folder, an expression token uses only the szTokenString member in the TOKEN structure.

The szTokenString string in an expression token is a string that contains the file name and file attributes used to identify a file. For information about the format required for szTokenString, see Inventory Rules Folder Tokens.

Note that your application is responsible for specifying a string containing a valid format as well as valid attributes for szTokenString. It is recommended that your application use the retrieve keyword so that the SMS API engine can retrieve the attribute value directly from the file, or that you use the FILETOKN.EXE utility provided with SMS to retrieve the attribute value from the file. Because there are several methods for calculating a CRC value, it is particularly important that you use the retrieve keyword or FILETOKN.EXE to calculate the CRC value, especially if you are unsure whether your CRC calculation uses the CCITT-CRC algorithm. For more information about the retrieve keyword, see Inventory Rules Folder Tokens.

Note that the inventory rules folder must contain at least one expression token. An inventory rules folder that does not contain one or more expression tokens cannot be committed to the site database.

In all other respects, the tokens for a inventory rules folder have the same behavior as tokens in a filter—expression tokens are connected by AND or OR operators, expression tokens can be grouped and ungrouped, and they can be deleted. However, the Inventory Agent program that scans for inventory uses the operators and groupings for a package's inventory rule in a specific manner. See Grouping Tokens in an Inventory Rules Folder.

Important To collect inventory on a package with tokens defined, the Inventory properties scalar for the package must be set to TRUE. The Inventory package scalar is used to indicate whether the SMS system scans for the package on all SMS computers at the current site and all sites below the current site in the site hierarchy. The SMS API engine sets the Inventory package scalar when the package is created. The SMS API engine sets this scalar to TRUE if the package has an Inventory rules subfolder and the inventory rules folder has the Inventory this package scalar set to TRUE.

When the Inventory properties scalar is set to TRUE and the inventory rules folder and package folder are committed, the package will be inventoried on all computers in the current site and all subsites below it in the site hierarchy.

If the Inventory properties scalar is set to FALSE, this package will not be inventoried. However, the tokens (that is, the inventory rule) for the package will be stored in the site database when the package folder is committed. After the package is committed, a user can use the SMS Administrator to enable inventory collection on the package.

Example

This example creates a package with the following inventory rule for Microsoft Word and enables inventory collection on that package:

file "winword.exe" CHECKSUM 20 200 7232
AND
file "winword6.reg" DATE 10/05/94

// Function to create a package folder with inventory rules for
// for Microsoft Word 6.0.
SMS_STATUS CreatePackageWithInventory( HANDLE hConnect )
// hConnect is a handle to a site database connection 
// established by SmsDataSourceConnect.

{
SMS_STATUS retStatus;
SMS_STATUS status;

// Open a package container.
HANDLE hPackageContainer;
DWORD cType;
cType = C_PACKAGE; // Set container type to package.

status = SmsOpenContainer( cType,    // Type of container.
                         hConnect, // Handle to database connection.
                         &hPackageContainer // Assign handle for 
                                     //container to hPackageContainer. 
                        );
    if (status != SMS_OK) {
        printf("Cannot open package container. Error code: %d\n", status);
        return status;
    }

// Create a package folder.
HANDLE hFolder;
status = SmsCreateFolder ( hPackageContainer, // Handle to parent 
                                            // container.
                         F_PACKAGE, // Folder type is package
                         NULL,         // SMS system assigns the 
                                       // ID. Therefore, this 
                                       // parameter is ignored.
                         &hFolder      // Handle to new folder.
                        );

// Set basic scalars for package so that inventory can be defined.
// This means set only Name.
int intValue;
SCALAR scalar;
// Set the Name scalar to Microsoft Word 6.0
char *pszScalarName = "Name"; // Name of the scalar to set.
SCALARTYPE scType = SCALAR_STRING; // Data type of scalar.
char *pszScalarValue = "Microsoft Word 6.0"; // Value to set.
// Assign the scalar data to the scalar structure.
scalar.pszName = pszScalarName;
scalar.scType  = scType;
scalar.dwLen = sizeof(pszScalarValue)-1;
scalar.pszValue = pszScalarValue;

// Use SmsSetScalar to use the SCALAR struct to set 
// the Name scalar for the folder.
status = SmsSetScalar( hFolder,   // Handle to folder containing 
                                 // the scalar to set.
                     &scalar     // Pointer to SCALAR struct 
                                 // containing value to set.
                   );

// Create an inventory rules folder.
HANDLE hInventoryFolder;
status = SmsCreateFolder ( hFolder, // Handle to parent 
                                            // folder.
                         F_INVENTORY, // Folder type is inventory
                         NULL,         // SMS system assigns the 
                                       // ID. Therefore, this 
                                       // parameter is ignored.
                         &hInventoryFolder   // Handle to new folder.
                        );

// Set the Inventory this package scalar to TRUE
// so that the SMS API engine will enable the Inventory this package
// scalar for the package.
pszScalarName = "Inventory this package"; // Name of the scalar to set.
scType = SCALAR_INT; // Data type of scalar.
intValue = TRUE; // Value to set.
// Assign the scalar data to the scalar structure.
scalar.pszName = pszScalarName;
scalar.scType  = scType;
scalar.dwValue = intValue;

// Use SmsSetScalar to use the SCALAR struct to set 
// the Name scalar for the folder.
status = SmsSetScalar( hInventoryFolder, // Handle to folder containing 
                                 // the scalar to set.
                     &scalar     // Pointer to SCALAR struct 
                                 // containing value to set.
                   );
// Set the token for inventory rule for winword.exe.
TOKEN token;
memset( &token, 0, sizeof(TOKEN) );
// Assign the string containing the rule to winword.exe to pszRule.
char *pszRule = "file \"winword.exe\" CHECKSUM 20 200 7232";
// Set szTokenString member to pszRule.
strcpy(token.szTokenString, pszRule);
// Use SmsAddToken to add the token to the package's inventory rule.
status = SmsAddToken( hInventoryFolder, // Handle to folder.
                    OP_AND,  // Use AND operator.
                    &token,  // Pointer to token to set.
                    AT_END );    // Add to end of token list.

// Set the token for inventory rule for winword6.reg.
memset( &token, 0, sizeof(TOKEN) );
// Assign the string containing the rule to winword.exe to pszRule.
pszRule = "file \"winword6.reg\" DATE 10/05/94";
// Set szTokenString member to pszRule.
strcpy(token.szTokenString, pszRule);
// Use SmsAddToken to add the token to the package's inventory rule.
status = SmsAddToken( hInventoryFolder, // Handle to folder.
                    OP_AND,  // Use AND operator.
                    &token,  // Pointer to token to set.
                    AT_END );    // Add to end of token list.

// Link the inventoryfolder to its parent.
status = SmsLinkFolder( hInventoryFolder );

// Link the package folder to its parent.
status = SmsLinkFolder( hFolder );

// Write the inventory folder to the site database.
status = SmsCommitFolder( hInventoryFolder );

// Write the new package folder to the site database.
retStatus = SmsCommitFolder( hFolder );

// Close inventory folder
status = SmsCloseFolder( hInventoryFolder );

// Close package folder
status = SmsCloseFolder( hFolder );

// Close Container
status = SmsCloseContainer( hPackageContainer );

return retStatus;
}