Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

It gets a little complicated obtaining a process handle from the object returned by Win32::Process. You have to ask it for the process id, and then use the Kernel API OpenProcess() to convert that back to a native process handle so that you can call GetProcessTimes().

Once you have the times, they come back as 64-bit values of 100 nano second periods since 1/jan 1601. Unpacking and formating the these time into something reasonable is awkward. My formatting routine is very lazy and doesn't do leading zeros, and you'll need to check the math on the conversion of the kernel and user times. There may be APIs available to do the formatting and converting.

#! perl -slw use strict; use Win32::Process; use Win32::API::Prototype; $|++; ApiLink( 'kernel32', 'BOOL GetProcessTimes( HANDLE hProcess, LPFILETIME lpCreationTime, LPFILETIME lpExitTime, LPFILETIME lpKernelTime, LPFILETIME lpUserTime )' ) or die $^E; ApiLink( 'kernel32', 'HANDLE OpenProcess( DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwProcessId )' ) or die $^E; ApiLink( 'kernel32', 'BOOL FileTimeToSystemTime( FILETIME* lpFileTime, LPSYSTEMTIME lpSystemTime )' ) or die $^E; sub SystemTimeToString{ my( $y, $M, $dow, $d, $h, $m, $s, $milli ) = unpack 's8', $_[ 0 ]; # $dow = (qw[ Sunday Monday Tuesday Wednesday Thursday Friday Satu +rday ])[$dow]; # $d = ( qw[ undef Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec +] )[ $d ]; return "$y/$M/$d $h:$m:$s.$milli"; } Win32::Process::Create( my $pObj, "C:\\windows\\system32\\notepad.exe", "notepad temp.txt", 0, NORMAL_PRIORITY_CLASS, "." ) or die $^E; print 'Paused'; <>; my $pid = $pObj->GetProcessID; print "pid: $pid"; my $hProc = OpenProcess( 0x0400, 1, $pid ) or die $^E; print "hproc: $hProc"; my( $c, $e, $k, $u ) = ('0'x8) x 4; my( $cs, $es ) = ('0'x16) x 2; GetProcessTimes( $hProc, $c, $e, $k, $u ) or die $^E; FileTimeToSystemTime( $c, $cs ) or die $^E; print 'Process created: ', SystemTimeToString( $cs ); FileTimeToSystemTime( $e, $es ) or die $^E; print 'Process ended: ', SystemTimeToString( $es ); printf '%7.5f %7.5f', map{ unpack( 'Nx[N]', $_ ) / 10e8 }$k, $u; __END__ P:\test>326090 Paused pid: 3616 hproc: 72 Process created: 2004/2/3 4:53:50.390 Process ended: 2004/2/3 4:53:50.796 0.00000 15.16372

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
Timing (and a little luck) are everything!


In reply to Re: Timing Windows commands by BrowserUk
in thread Timing Windows commands by eyepopslikeamosquito

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others taking refuge in the Monastery: (10)
    As of 2014-08-20 09:36 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (109 votes), past polls