DateTime Conversion Nightmare

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chris Malone

    #1

    DateTime Conversion Nightmare


    I'm trying to convert into friendly format the "LastModifi ed" 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<SCORE Array.GetUpperB ound(0);i++)
    {

    ConnectionOptio ns oConn = new ConnectionOptio ns();
    oConn.Username =
    oConn.Password =

    System.Manageme nt.ManagementSc ope oMs = new
    System.Manageme nt.ManagementSc ope("\\\\" + SCOREArray[i] +
    "\\root\\cimv2" , oConn);
    System.Manageme nt.ObjectQuery oQuery = new
    System.Manageme nt.ObjectQuery( "select * FROM CIM_Datafile WHERE Name =
    'c:\\\\winnt\\\ \memory.dmp'");


    ManagementObjec tSearcher oSearcher = new
    ManagementObjec tSearcher(oMs,o Query);
    ManagementObjec tCollection oReturnCollecti on = oSearcher.Get() ;

    foreach( ManagementObjec t oReturn in oReturnCollecti on )
    {
    try
    {

    ListBox1.Items. Add(SCOREArray[i] + " - Modify date is : " +
    (oReturn["LastModifi ed"].ToString()));
    }
    catch(System.Ex ception gen_ex)
    { ListBox1.Items. Add(SCOREArray[i] + 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

  • Yunus Emre ALPÖZEN [MCSD.NET]

    #2
    Re: DateTime Conversion Nightmare

    Take a look at this:

    http://msdn.microsoft.com/library/de...arsetopic2.asp

    --

    Thanks,
    Yunus Emre ALPÖZEN
    BSc, MCSD.NET

    "Chris Malone" <persillade@hot mail.com> wrote in message
    news:1118430806 .225313.130210@ g44g2000cwa.goo glegroups.com.. .[color=blue]
    >
    > I'm trying to convert into friendly format the "LastModifi ed" 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<SCORE Array.GetUpperB ound(0);i++)
    > {
    >
    > ConnectionOptio ns oConn = new ConnectionOptio ns();
    > oConn.Username =
    > oConn.Password =
    >
    > System.Manageme nt.ManagementSc ope oMs = new
    > System.Manageme nt.ManagementSc ope("\\\\" + SCOREArray[i] +
    > "\\root\\cimv2" , oConn);
    > System.Manageme nt.ObjectQuery oQuery = new
    > System.Manageme nt.ObjectQuery( "select * FROM CIM_Datafile WHERE Name =
    > 'c:\\\\winnt\\\ \memory.dmp'");
    >
    >
    > ManagementObjec tSearcher oSearcher = new
    > ManagementObjec tSearcher(oMs,o Query);
    > ManagementObjec tCollection oReturnCollecti on = oSearcher.Get() ;
    >
    > foreach( ManagementObjec t oReturn in oReturnCollecti on )
    > {
    > try
    > {
    >
    > ListBox1.Items. Add(SCOREArray[i] + " - Modify date is : " +
    > (oReturn["LastModifi ed"].ToString()));
    > }
    > catch(System.Ex ception gen_ex)
    > { ListBox1.Items. Add(SCOREArray[i] + 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
    >[/color]


    Comment

    • Manfred Braun

      #3
      Re: DateTime Conversion Nightmare

      Hi,

      I would use the mgmtclassgen generator from VS [see
      http://msdn.microsoft.com/library/de...lassgenexe.asp ]
      , export a class containing the WBEMDateTime and cut and paste the
      conversion code .... That's what I've done.

      Best regards,
      Manfred Braun

      (Private)
      Mannheim
      Germany

      mailto:_manfred .braun_@manfbra un.de
      (Remove the anti-spam-underscore to mail me!)

      "Chris Malone" <persillade@hot mail.com> wrote in message
      news:1118430806 .225313.130210@ g44g2000cwa.goo glegroups.com.. .[color=blue]
      >
      > I'm trying to convert into friendly format the "LastModifi ed" 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<SCORE Array.GetUpperB ound(0);i++)
      > {
      >
      > ConnectionOptio ns oConn = new ConnectionOptio ns();
      > oConn.Username =
      > oConn.Password =
      >
      > System.Manageme nt.ManagementSc ope oMs = new
      > System.Manageme nt.ManagementSc ope("\\\\" + SCOREArray[i] +
      > "\\root\\cimv2" , oConn);
      > System.Manageme nt.ObjectQuery oQuery = new
      > System.Manageme nt.ObjectQuery( "select * FROM CIM_Datafile WHERE Name =
      > 'c:\\\\winnt\\\ \memory.dmp'");
      >
      >
      > ManagementObjec tSearcher oSearcher = new
      > ManagementObjec tSearcher(oMs,o Query);
      > ManagementObjec tCollection oReturnCollecti on = oSearcher.Get() ;
      >
      > foreach( ManagementObjec t oReturn in oReturnCollecti on )
      > {
      > try
      > {
      >
      > ListBox1.Items. Add(SCOREArray[i] + " - Modify date is : " +
      > (oReturn["LastModifi ed"].ToString()));
      > }
      > catch(System.Ex ception gen_ex)
      > { ListBox1.Items. Add(SCOREArray[i] + 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
      >[/color]


      Comment

      • Chris Malone

        #4
        Re: DateTime Conversion Nightmare

        Actually I figured it out over the weekend and used
        ManagementDateT imeConverter.To DateTime. This is exactly what I needed.

        chris

        Comment

        Working...