Wednesday, December 5, 2007

How to list all installed sevice packs in C#

// Create WMI connection
ConnectionOptions
options = new ConnectionOptions();

string
machine = "127.0.0.1";

ManagementPath
path = new ManagementPath(String.Format(
@"\\{0}\root\cimv2", machine));
ManagementScope
scope = new ManagementScope(path, options);

scope.Connect();


// Query

ObjectQuery
query = new ObjectQuery(
"Select * from Win32_QuickFixEngineering");

ManagementObjectSearcher
managerTemp =
new ManagementObjectSearcher(scope, query);

//Get the results

ManagementObjectCollection
returnCollection = managerTemp.Get();


foreach
(ManagementObject managementObject in returnCollection)

{
System.Console.WriteLine("*** New Item: ");
foreach
(PropertyData propertyData in managementObject.Properties)

{
System.Console.WriteLine(" {0} : {1}",
propertyData.Name,
propertyData.Value);
}
}

No comments: