G
Guest
Greetings everybody!
I have a short but hopefully simple question. If anybody can give me some
direction, I would greatly appreciate it.
I am in the process of writing a small console utility that will pull in a
computers hotfix information via wmi’s win32_QuickFixEngineering. The code
listed below works, the only bump I can’t seem to get over is the way the
data is outputted. If at all possible, can you help me output the data in a
comma delimited format? Any help would be greatly appreciated – thank you so
much in advance.
//Code:
//Authored by Thomas Mshar / Ray Cables / Brad Budgick
//Wachovia Desktop Services / Charlotte Trade Floor Support
using System;
using System.Management;
class Constants
{
public const string UserID = "test\test";
public const string Password = "test";
public const string ComputerName = ".";
public const string NameSpace = "Root\\CIMv2";
public const string WMIClass = "Win32_QuickFixEngineering";
}
class WMISample
{
public static int Main(string[] args)
{
ConnectionOptions options = new ConnectionOptions();
options.Username = Constants.UserID;
options.Password = Constants.Password;
options.Authentication = AuthenticationLevel.Default;
options.Impersonation = ImpersonationLevel.Impersonate;
ManagementScope scope = new ManagementScope();
scope.Path = new ManagementPath("\\\\" + Constants.ComputerName
+
"\\" + Constants.NameSpace);
scope.Options = options;
try {
scope.Connect();
}
catch (Exception Err)
{
Console.WriteLine("Failed to connect: " + Err.Message);
return 1;
}
ManagementClass WMIClass = new
ManagementClass(Constants.WMIClass);
WMIClass.Scope = scope;
ManagementObjectCollection WMIInstanceCollection =
WMIClass.GetInstances();
foreach (ManagementObject WMIInstance in WMIInstanceCollection)
{
Console.WriteLine();
PropertyDataCollection.PropertyDataEnumerator
propertyEnumerator =
WMIInstance.Properties.GetEnumerator();
while (propertyEnumerator.MoveNext())
{
PropertyData property =
(PropertyData)propertyEnumerator.Current;
Console.WriteLine(property.Name + " = " +
property.Value);
//Console.WriteLine(property.Name + " = " + property.Value + " = "
+ property.type);
}
}
return 0;
}
}
//END Code
I have a short but hopefully simple question. If anybody can give me some
direction, I would greatly appreciate it.
I am in the process of writing a small console utility that will pull in a
computers hotfix information via wmi’s win32_QuickFixEngineering. The code
listed below works, the only bump I can’t seem to get over is the way the
data is outputted. If at all possible, can you help me output the data in a
comma delimited format? Any help would be greatly appreciated – thank you so
much in advance.
//Code:
//Authored by Thomas Mshar / Ray Cables / Brad Budgick
//Wachovia Desktop Services / Charlotte Trade Floor Support
using System;
using System.Management;
class Constants
{
public const string UserID = "test\test";
public const string Password = "test";
public const string ComputerName = ".";
public const string NameSpace = "Root\\CIMv2";
public const string WMIClass = "Win32_QuickFixEngineering";
}
class WMISample
{
public static int Main(string[] args)
{
ConnectionOptions options = new ConnectionOptions();
options.Username = Constants.UserID;
options.Password = Constants.Password;
options.Authentication = AuthenticationLevel.Default;
options.Impersonation = ImpersonationLevel.Impersonate;
ManagementScope scope = new ManagementScope();
scope.Path = new ManagementPath("\\\\" + Constants.ComputerName
+
"\\" + Constants.NameSpace);
scope.Options = options;
try {
scope.Connect();
}
catch (Exception Err)
{
Console.WriteLine("Failed to connect: " + Err.Message);
return 1;
}
ManagementClass WMIClass = new
ManagementClass(Constants.WMIClass);
WMIClass.Scope = scope;
ManagementObjectCollection WMIInstanceCollection =
WMIClass.GetInstances();
foreach (ManagementObject WMIInstance in WMIInstanceCollection)
{
Console.WriteLine();
PropertyDataCollection.PropertyDataEnumerator
propertyEnumerator =
WMIInstance.Properties.GetEnumerator();
while (propertyEnumerator.MoveNext())
{
PropertyData property =
(PropertyData)propertyEnumerator.Current;
Console.WriteLine(property.Name + " = " +
property.Value);
//Console.WriteLine(property.Name + " = " + property.Value + " = "
+ property.type);
}
}
return 0;
}
}
//END Code