#! c:\perl\bin\perl.exe #--------------------------------------------------------- # keytime.pl # Retrieves LastWrite time from Registry keys # # usage: keytime.pl # ex: keytime.pl HKEY_LOCAL_MACHINE\Software\Microsoft # # Thanks to Dave Roth for providing the Win32::API::Prototype # module, and for assisting with how to retrieve the information # # Copyright 2000/2001 H. Carvey keydet89@yahoo.com #--------------------------------------------------------- use strict; use Win32::API::Prototype; use Win32::TieRegistry(Delimiter=>"/"); my @month = qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/; my @day = qw/Sun Mon Tue Wed Thu Fri Sat/; my $server = Win32::NodeName; my $regkey = shift || die "You must enter a Registry key.\n"; $regkey =~ s/\\/\//g; # Registry key to check my $remote = $Registry->{"//$server/".$regkey}; die "Could not locate $regkey.\n" unless ($remote); # Get key info #my %info = $remote->Information; my %info; die "Key has no Information.\n" unless (%info = $remote->Information); ApiLink('kernel32.dll', 'BOOL FileTimeToLocalFileTime(FILETIME *lpFileTime, LPFILETIME lpLocalFileTime )' ) || die "Can not locate FileTimeToLocalFileTime()"; ApiLink('kernel32.dll', 'BOOL FileTimeToSystemTime(FILETIME *lpFileTime, LPSYSTEMTIME lpSystemTime )' ) || die "Can not locate FileTimeToSystemTime()"; # The FILETIME structure can be broken down and saved to be # used at a later date for conversions, etc. #my ($high,$low) = unpack("L2",$info{'LastWrite'}); #print "High: $high\n"; #print "Low : $low\n"; my $pFileTime = $info{'LastWrite'}; my $lpLocalFileTime; # Create an empty SYSTEMTIME structure of 8 short ints # pack()'d together my $pSystemTime = pack("S8", 0); # Translate the FILETIME to LOCALFILETIME if (FileTimeToLocalFileTime($pFileTime,$lpLocalFileTime)) { # call FileTimeToSystemTime() if (FileTimeToSystemTime($lpLocalFileTime,$pSystemTime)) { # Unpack the 8 WORD values from the system time structure.... # year,month,dayofweek,day,hour,minute,sec,milli my @time = unpack("S8", $pSystemTime); $time[5] = "0".$time[5] if ($time[5] =~ m/^\d$/); $time[6] = "0".$time[6] if ($time[6] =~ m/^\d$/); my $timestr = $day[$time[2]]." ".$time[1]."/".$time[3]."/".$time[0]. " ".$time[4].":".$time[5].":".$time[6].":".$time[7]; print "$timestr\n"; print "\n"; } }