You enumerate the software updates, in Microsoft System Center Configuration Manager 2007, by creating an instance of the CCMUpdatesDeployment COM class and by using the EnumerateUpdates method. This example enumerates all updates that are deployed and available in the client UI.
To enumerate software updates
-
Create a CCMUpdatesDeployment instance by using the CCMUpdatesDeployment COM class.
-
Enumerate the updates by using the using the EnumerateUpdates method.
Example
The following example method shows how to enumerate the software updates by creating an instance of the CCMUpdatesDeployment COM class and using the EnumerateUpdates method.
Note |
---|
This example enumerates all software updates that are available in the client UI, both optional and mandatory. |
In the example, the LocaleID property is hard-coded to English (U.S.). If you need the locale for non-U.S. installations, you can get it from the SMS_Identification Server WMI Class LocaleID property or use the LocaleID value from the Configuration Manager Context Qualifiers.
For information about calling the sample code, see How to Call Configuration Manager COM Automation Objects
Visual Basic Script | Copy Code |
---|---|
Sub EnumerateUpdates() ' Initialize variables. dim updatesDeployment dim progress dim updateCount dim update dim progressStage dim percentComplete dim errorCode dim updateData dim notify ' Create an UpdatesDeployment instance. set updatesDeployment = CreateObject ("UDA.CCMUpdatesDeployment") ' Get the current updates. Set updatesColl = updatesDeployment.EnumerateUpdates( 2, 0, progress ) ' Get a count of the current updates. updateCount = updatesColl.GetCount() ' Determine whether there are any updates to enumerate. if updatecount = 0 then WScript.echo "No updates found." else ' Loop through the updates. for nIndex = 0 To updateCount-1 Set update = updatesColl.GetUpdate(nIndex) WScript.echo "Update ID: " & update.GetId() if update.GetEnforcementDeadline() <> Null then WScript.echo "Enforcement Deadline: " & update.GetEnforcementDeadline() else WScript.echo "Enforcement Deadline: None" end if WScript.echo "Bulletin ID: " & update.GetBulletinId() WScript.echo "Article ID: " & update.GetArticleId() WScript.echo "Name: " & update.GetName(1033) WScript.echo "Summary: " & update.GetSummary(1033) WScript.echo "Information Link: " & update.GetInfoLink(1033) WScript.echo "Manufacturer: " & update.GetManufacturer(1033) WScript.echo "State: " & update.GetState() update.GetProgress progressStage, percentComplete, errorCode WScript.echo "Progress Stage: " & progressStage WScript.echo "Percent Complete: " & percentComplete WScript.echo "Error Code: " & errorCode WScript.echo "Notification Option: " & update.GetNotificationOption() WScript.echo " " next end if End Sub |
C# | Copy Code |
---|---|
public void EnumerateSoftwareUpdates() { try { // Initialize reference variables needed later. object progress = null; object progressStage = null; object percentComplete = null; object errorCode = null; // Create UpdatesDeployment instance. UPDATESDEPLOYMENTLib.CCMUpdatesDeploymentClass newCCMUpdatesDeployment = new UPDATESDEPLOYMENTLib.CCMUpdatesDeploymentClass(); // Get the current updates. UPDATESDEPLOYMENTLib.ICCMUpdatesCollection updatesCollection = newCCMUpdatesDeployment.EnumerateUpdates(2, true, ref progress); // Get a count of the available updates. int updateCount = updatesCollection.GetCount(); // Check whether there are any updates to enumerate. if (updateCount == 0) { Console.WriteLine("No updates found."); } else { // Loop through the updates. for (int arrayIndex = 0; arrayIndex < updateCount; arrayIndex++) { UPDATESDEPLOYMENTLib.ICCMTargetedUpdate update = updatesCollection.GetUpdate(arrayIndex); Console.WriteLine("Update ID: " + update.GetID()); // Get enforcement deadline value to check for no enforcement deadline. // In this case, GetEnforcementDeadline does not return a 'null', but // a date with the year 1899. DateTime tempEnforcementDeadline = update.GetEnforcementDeadline(); int tempYear = tempEnforcementDeadline.Year; if (tempYear.CompareTo(1899)== 0) { Console.WriteLine("Enforcement Deadline: None "); } else { Console.WriteLine("Enforcement Deadline: " + update.GetEnforcementDeadline()); } Console.WriteLine("Article ID: " + update.GetArticleId()); Console.WriteLine("Name: " + update.GetName(1033)); Console.WriteLine("Summary: " + update.GetSummary(1033)); Console.WriteLine("Information Link: " + update.GetInfoLink(1033)); Console.WriteLine("Manufacturer: " + update.GetManufacturer(1033)); Console.WriteLine("State: " + update.GetState()); update.GetProgress(ref progressStage, ref percentComplete, ref errorCode); Console.WriteLine("Progress Stage: " + progressStage); Console.WriteLine("Percent Complete: " + percentComplete); Console.WriteLine("Error Code: " + errorCode); Console.WriteLine("Notification Option: " + update.GetNotificationOption()); Console.WriteLine(" "); }; } // Output success message. Console.WriteLine("Ran EnumerateSoftwareUpdates."); } catch (COMException ex) { Console.WriteLine("Failed to run EnumerateSoftwareUpdates method. Error: " + ex.Message); throw; } } |
Compiling the Code
This C# example requires:
Namespaces
System
System.Runtime.InteropServices
UPDATESDEPLOYMENTLib COM Automation Library
COM Automation
The reference that is needed for early binding is UpdatesDeploymentAgent 1.0 Type Library. This creates a type library reference named UPDATESDEPLOYMENTLib. The early binding object name for the Control Panel Manager is CCMUpdatesDeploymentClass.
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
Send comments about this topic to Microsoft.