1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Display the start time of a process

Discussion in 'PowerShell' started by Joe Caverly, Mar 8, 2014.

  1. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    680
    Likes Received:
    8
    This batch file demonstrates how to find the start time of a process using PowerShell and TCC.

    Code:
    ::+---------------------------------------------------------------------
    ::| STARTTIME.BTM - Display the start time of a process using
    ::|  PowerShell and TCC LE
    ::| 2014-03-08
    ::| Joe Caverly
    ::|
    ::| TCC LE 13.03.51 Windows XP
    ::| TCC 16.00.41  Windows Vista SP2
    ::| PowerShell 2.0
    ::|
    ::| In TCC you can use %@agedate[%@processtime[%@pid[theprocess.exe,0],4]]
    ::|  to find the start time of a process.
    ::|
    ::| NOTE: I have PowerShell Set-ExecutionPolicy Unrestricted
    ::|  If this does not work on your system, check this setting
    ::|
    ::| TODO: More error checking
    ::|---------------------------------------------------------------------
    @setlocal
    @echo off
    iff %# eq 0 then
      echo USAGE: starttime.btm procname
      echo  starttime.btm tcc
      quit
    endiff
    set theproc=%1
    iff %@right[4,%theproc] eq .exe then
      echo Do not use .exe on the end of the process name.
      quit
    endiff
    set thefile=%@unique[]
    setdos /X-5
    echo $a = get-process -Name %theproc > starttime.ps1
    echo $a.starttime | Out-File -FilePath %thefile >> starttime.ps1
    type starttime.ps1
    powershell -File starttime.ps1 > nul
    iff %@filesize[%thefile] gt 2 then
      echo PowerShell: %@line[%thefile,1]
      ::
      :: If this is not being run in TCCLE
      ::
      iff %_cmdproc ne TCCLE then
        set thepid=%@pid[%theproc.exe]
        echo  TCC: %@agedate[%@processtime[%thepid,0],4]
      endiff
    endiff
    if %@filesize[%thefile] lt 3 echo Could not find process %theproc
    ::
    :: Cleanup
    ::
    if exist %thefile del /q %thefile
    if exist starttime.ps1 del /q starttime.ps1
    endlocal
    Since @AGEDATE and @PROCESSTIME are not supported in TCC/LE, this demonstrates how to find the start time of a process using PowerShell from within TCC/LE.

    Joe
     

Share This Page