17

Is it possible to use wmic or powershell to find out how long a process has been running for?

If not, is there any other mean to obtain this information from Windows OS?

Anthony Kong
  • 4,868
  • 11
  • 48
  • 80

1 Answers1

29

Use New-TimeSpan –Start; passing the StartTime property of the process which you want to know how long has been running. Here an example which shows how long notepad has been running:

PS C:\> New-TimeSpan -Start (get-process notepad).StartTime


Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 2
Milliseconds      : 920
Ticks             : 29200041
TotalDays         : 3.379634375E-05
TotalHours        : 0.00081111225
TotalMinutes      : 0.048666735
TotalSeconds      : 2.9200041
TotalMilliseconds : 2920.0041
krowe
  • 5,493
  • 1
  • 24
  • 31
  • 12
    And to do this by process id: `New-TimeSpan -Start (get-process -id 4).StartTime`, you may have to be an admin to get this information for some processes. – Nick Nov 08 '16 at 14:27
  • Kept getting conversion errors so switched to syntax `(Get-Process notepad).StartTime | % {New-TimeSpan -Start $_}` to get by on Server 2012 R2. What an old server this is! – Vomit IT - Chunky Mess Style Oct 10 '21 at 21:22