Hi
Thanks for your response.
I want to get the readable "Dos" date time from the cryptic CreationTime
given by GetProcessTimes.
The following is my code...and the output is not readable and is wrong.
Thanks in advance,
Jeremy A.
use Win32::API;
$pid = "3228"; #processid - your process id goes here.
my $OpenProcess = new Win32::API( 'kernel32.dll', 'OpenProcess', [N,I,N], N
) || die "Can not link to open proc";
my $GetProcessTimes = new Win32::API('kernel32',
'GetProcessTimes',[I,P,P,P,P], 'I');
my $FileTimeToDosDateTime = new Win32::API('kernel32',
'FileTimeToDosDateTime',[P,P,P], 'I');
$PROCESS_QUERY_INFORMATION = 0x0400;
$PROCESS_VM_READ = 0x0010;
my $lpCreationTime = pack 'I2', 0, 0; # 100ns since 1/1/1601
my $lpExitTime = pack 'I2', 0, 0;
my $lpKernelTime = pack 'I2', 0, 0;
my $lpUserTime = pack 'I2', 0, 0;
my( $hProcess ) = $OpenProcess->Call( $PROCESS_QUERY_INFORMATION |
$PROCESS_VM_READ, 0, $pid );
my $ret = $GetProcessTimes-> Call($hProcess, $lpCreationTime, $lpExitTime,
$lpKernelTime, $lpUserTime);
my $Date = pack 'I3',0,0,0;
my $Time = pack 'I3',0,0,0;
$FileTimeToDosDateTime->Call($lpCreationTime,$Date,$Time);
my ($dom,$month,$year) = unpack("I3",$Date);
my ($sec,$min,$hour) = unpack("I3",$Time);
print "$dom $month $year $sec $min $hour";
At 05:13 PM 10/28/2004, you wrote:
Jeremy A wrote:
> Hi all,
>
> I have a Win32 API problem. I want to get the creation time for a
specified
> process.
> I must use "GetProcessTimes" through perl's Win32::API interface.
> what will the code be.
Here's my hires timer script that you can extract what you need from it.
#!perl -w --
use strict;
use Win32::API;
our $debug = 0;
our $QueryPerformanceCounter; # API function object once set in init
our $QueryPerformanceFrequency; # API function object once set in init
our $QPC_Freq; # computed freq of QPC in seconds
our $QPC_Ovhd; # computed overhead of QPC API call in seconds
our $GetProcessTimes; # get kernel/user times for process
our $GetCurrentProcess; # get process handle
# test code
init_QPC ();
print "\n";
printf "QPC_Freq: %9.6f usecs (%u per sec)\n", 100 / $QPC_Freq, $QPC_Freq;
printf "QPC_Ovhd: %9.6f usecs\n", $QPC_Ovhd * 100;
# test loop
init_getCPU ();
my @start = getCPU (); # get CPU usage before
print "[EMAIL PROTECTED] = @start\n";
my $tot_start = start_PC_timer ();
# stuff to time goes in here **
for (1 .. 10) {
# start timer
my $start = start_PC_timer ();
# time the get GTC res routine as a test of timer
my $gtc_res = get_GTC_resolution ();
printf "GTC res: %.6f msecs\n", $gtc_res;
# stop timer
my $et = stop_PC_timer ($start);
printf "ET : %.6f secs\n", $et;
}
# stuff to time goes in here **
my $tot_et = stop_PC_timer ($tot_start);
my @end = getCPU ();# get CPU usage after
print "[EMAIL PROTECTED] = @end\n";
my @usage = compute_usage ([EMAIL PROTECTED], [EMAIL PROTECTED], $tot_et);
print "\n";
printf "Kernel : %.6f%%\n", $usage[0];
printf "User : %.6f%%\n", $usage[1];
print "\n";
exit;
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Time GetTickCount resolution - test routine
sub get_GTC_resolution {
my $total = 0;
my $max_loops = 100;
my $tot_loops = 0;
for (1 .. $max_loops) {
my $loops = 0;
my $count1 = Win32::GetTickCount();
my $count2 = $count1;
while ($count1 == $count2) {
$count2 = Win32::GetTickCount();
$loops++;
}
$total += $count2 - $count1;
$tot_loops += $loops;
}
my $res = $total / $max_loops;
printf "GetTickCount min res: %u ms, ", $res if $debug;
print "Took ", $tot_loops / $max_loops, " loops on average\n\n" if $debug;
return $res;
}
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub init_QPC { # set 4 global vrbls for using timing routines
$QueryPerformanceCounter = new Win32::API('kernel32',
'QueryPerformanceCounter', [qw(P)], 'I') or die
'Failed to get QueryPerformanceCounter: ', Win32::FormatMessage (
Win32::GetLastError ()); # set global
$QueryPerformanceFrequency = new Win32::API('kernel32',
'QueryPerformanceFrequency', [qw(P)], 'I') or die
'Failed to get QueryPerformanceFrequency: ', Win32::FormatMessage (
Win32::GetLast