Windows Perl Scripting Forums » Perl

Win32::OLE and Variants

(3 posts)
  • Started 12 years ago by keydet89
  • Latest reply from keydet89

Tags:


  1. keydet89
    Member

    I'm looking for a way to get the InstallDate value from Win32 classes (ie, Win32_Service) and translate that into something readable. Also, is there a way to translate it into something easily searchable, using '<' or '>'?

    Thanks,

    Harlan
    Posted 12 years ago #
  2. Dave
    Perl guy

    Hey Harlan! Welcome to the forums! (I would recognize that username anywhere) :D

    The 'InstallDate' property of a Win32_Service WMI class is a DATETIME datatype. Essentially it is a long string with the date and time all slapped together. You can use regex to break apart the components:

    sub FormatDate
    {
        my( $Date ) = @_;
        $Date =~ s/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2}).*/$1.$2.$3 $4:$5:$6/;
        return( $Date );
    }



    If you pass in a WMI DATETIME stamp into FormatDate() it will return something like:
    2006.09.25 09:54:21

    Alternatively, once you rip it apart you could easily feed it into localtime():


    use Time::Local;

    sub FormatDate2
    {
        my( $Date ) = @_;
        my @TimeData = reverse ( $Date =~ /^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/ );
        $TimeData[4] -= 1;  # Adjust the month for timelocal()
        return( scalar localtime( timelocal( @TimeData ) ) );

    }



    However, the key here is that the Win32_Service.InstallDate property is not guaranteed to be non-empty. From MSDN:
    This property does not require a value to indicate that the object is installed.
    Posted 12 years ago #
  3. keydet89
    Member

    Dave,

    Thanks. Yeah, that's the issue...the InstallDate value is not guaranteed to be populated. Ugh. Thanks, MS!! So then, what's the point of having a value that isn't guaranteed to have anything in it?

    Sheesh.

    Harlan
    Posted 12 years ago #

RSS feed for this topic

Reply

You must log in to post.