Compartir a través de


How to Reset the Software Inventory Cache

Applies To: System Center Configuration Manager 2007, System Center Configuration Manager 2007 R2, System Center Configuration Manager 2007 R3, System Center Configuration Manager 2007 SP1, System Center Configuration Manager 2007 SP2

In Microsoft System Center Configuration Manager 2007, you reset the software inventory cache by connecting to the inventory agent namespace and deleting the inventory action status instance for software inventory.

To reset the software inventory cache

  1. Connect to the inventory agent namespace (root\ccm\invagt).

  2. Delete the inventory action status instance for software inventory ({00000000-0000-0000-0000-000000000002}).

Example

The following example method shows how to reset the software inventory cache by connecting to the inventory agent namespace and deleting the inventory action status instance for software inventory.

For information about calling the sample code, see How to Call a Configuration Manager Object Class Method by Using WMI

Sub ResetSoftwareInventoryCache()

    ' Get a connection to the "root\ccm\invagt" namespace.
    Dim locator
    Set locator = CreateObject("WbemScripting.SWbemLocator")
    Dim services
    Set services = locator.ConnectServer( , "root\ccm\invagt")
      
    ' Delete the specified InventoryActionStatus instance.
    services.Delete "InventoryActionStatus.InventoryActionID='{00000000-0000-0000-0000-000000000002}'"      

    ' Display message.
    wscript.echo "Reset Software Inventory cache."
    
End Sub
public void ResetSoftwareInventoryCache()
{
    try
    {
        // Define the scope (namespace).
        ManagementScope inventoryAgentScope = new ManagementScope(@"root\ccm\invagt");
        
        // Load the class that you want to work with.
        ManagementClass inventoryClass = new ManagementClass(inventoryAgentScope.Path.Path, "InventoryActionStatus", null);

        // Query the class for the InventoryActionID object (create query, create searcher object, execute query).
        ObjectQuery query = new ObjectQuery("SELECT * FROM InventoryActionStatus WHERE InventoryActionID = '{00000000-0000-0000-0000-000000000002}'");
        ManagementObjectSearcher searcher = new ManagementObjectSearcher(inventoryAgentScope, query);
        ManagementObjectCollection queryResults = searcher.Get();
                        
        // Enumerate the collection to get to the result (there should only be one item returned from the query).
        foreach (ManagementObject result in queryResults)
        {
            // Display message and delete the object.
            Console.WriteLine("Resetting Software Inventory cache.");
            result.Delete();
        }
    }

    catch (System.Management.ManagementException ex)
    {
        Console.WriteLine("Failed to run action. Error: " + ex.Message);
        throw;
    }
}

Compiling the Code

This C# example requires:

Namespaces

System.Management

Robust Programming

For more information about error handling, see About Configuration Manager Errors.

Security

For more information about securing Configuration Manager applications, see Securing Configuration Manager Applications.

See Also

Concepts

System Center Configuration Manager Software Development Kit
Configuration Manager Inventory
About Configuration Manager Inventory
Configuration Manager Client Programming