如何重置软件清单缓存

在 Configuration Manager中,通过连接到清单代理命名空间并删除软件清单的清单操作状态实例来重置软件清单缓存。

重置软件清单缓存

  1. (root\ccm\invagt) 连接到清单代理命名空间。

  2. 删除软件清单 ({00000000-0000-0000-0000-000000000002}) 的清单操作状态实例。

示例

以下示例方法演示如何通过连接到清单代理命名空间并删除软件清单的清单操作状态实例来重置软件清单缓存。

有关调用示例代码的信息,请参阅如何使用 WMI 调用 Configuration Manager 对象类方法


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;  
    }  
}  

编译代码

此 C# 示例需要:

命名空间

System.Management

可靠编程

有关错误处理的详细信息,请参阅关于Configuration Manager错误

.NET Framework 安全性

有关保护Configuration Manager应用程序的详细信息,请参阅Configuration Manager基于角色的管理

另请参阅

Configuration Manager软件开发工具包
关于Configuration Manager清单