knackko wrote:

> Hello people!
> 
> I am working with Win32::Tieregistry in order to know the last
> modifications on the registry (with the *Information* method). But i
> fail to display it with print or printf. The module doc said :
> 
> */Information
> %info= $key->Information
> @items= $key->Information( @itemNames );
> /*/Returns the following information about a Registry key:
> *LastWrite*
> A FILETIME structure indicating when the key was last modified and
> packed into a Perl string./
> 
> I tried with
> */printf("%04d/%02d/%02d%02d:%02d:%02d",$key->Information{"LastWrite"};/*
> i've got :
> 
> Use of uninitialized value in printf at regsurvey.pl line 50.
> */ÐgçÄ/00/0000:00:00ÐgçÄ/00/0000:00:00/ *
> *
> Is there anybody who has successfully display the filetime? can you help
> me?

Firstly - always provide a complete and small executable snippet.

This uses BigInt, but I've seen it done without resortig to that,
but I think it's safer to use it.

use Win32;
use Win32::TieRegistry (Delimiter => '\\', ArrayValues => 0);

my $key = 'HKEY_LOCAL_MACHINE\SOFTWARE\InterVideo';
my $Key = $Registry->{$key} or die "Can't read $key: $^E";

my @FT;

if (1) {        # pick one of these two methods
        my %items = $Key->Information;
        @FT = unpack 'II', $items{LastWrite};
} else {
        my @itemNames = ('LastWrite');
        my @items = $Key->Information(@itemNames);
        @FT = unpack 'II', $items[0];
}

my $epoch = FileTimeToEpoch (@FT);
print scalar localtime $epoch, "\n";
exit;

#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

# FileTime: 100-ns intervals since January 1, 1601 (64 bits)
# Epoch: seconds since January 1, 1970 (32 bits)

sub FileTimeToEpoch {
        my $lsFT = shift;
        my $msFT = shift;
        require Math::BigInt;

my $bias1601 = Math::BigInt->new(11644473600);  # 1601->1970 bias (134774 days)
my $nsecbias = Math::BigInt->new(10000000);     # secs->100-nsecs multiplier

my $ls = Math::BigInt->new($lsFT);
my $ms = Math::BigInt->new($msFT);
my $epoch = Math::BigInt::numify ((($ms << 32) | $ls) / $nsecbias - $bias1601);
return 0 if $epoch < 0; # in case prior to 1970/01/01
return $epoch;

}

__END__

-- 
  ,-/-  __      _  _         $Bill Luebkert    Mailto:[EMAIL PROTECTED]
 (_/   /  )    // //       DBE Collectibles    Mailto:[EMAIL PROTECTED]
  / ) /--<  o // //      Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_    http://dbecoll.tripod.com/ (My Perl/Lakers stuff)


_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to