DateTime Conversion Nightmare

C

Chris Malone

I'm trying to convert into friendly format the "LastModified" property
of an object returned via WMI from remote servers. Every attempt to
manipulate that using DateTime has bombed with "specified cast not
valid" errors, etc. Here is the code:

for(i=0;i<SCOREArray.GetUpperBound(0);i++)
{

ConnectionOptions oConn = new ConnectionOptions();
oConn.Username =
oConn.Password =

System.Management.ManagementScope oMs = new
System.Management.ManagementScope("\\\\" + SCOREArray +
"\\root\\cimv2", oConn);
System.Management.ObjectQuery oQuery = new
System.Management.ObjectQuery("select * FROM CIM_Datafile WHERE Name =
'c:\\\\winnt\\\\memory.dmp'");


ManagementObjectSearcher oSearcher = new
ManagementObjectSearcher(oMs,oQuery);
ManagementObjectCollection oReturnCollection = oSearcher.Get();

foreach( ManagementObject oReturn in oReturnCollection )
{
try
{

ListBox1.Items.Add(SCOREArray + " - Modify date is : " +
(oReturn["LastModified"].ToString()));
}
catch(System.Exception gen_ex)
{ ListBox1.Items.Add(SCOREArray + gen_ex.Message);
}


An example of the output of this property is
"20050105160751.664062-360". I'm having a terrible time converting that
into a user-friendly date.

Any assistance appreciated.

chris
 
C

Chris Malone

Actually I figured it out over the weekend and used
ManagementDateTimeConverter.ToDateTime. This is exactly what I needed.

chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top