Win32_Process
has the property CreationDate
, that despite the name is a Datetime. To know the idle time of a program, just discover the total time and subtract the user’s time (UserModeTime
) and time spent core (KernelModeTime
)
An example, using the standard C classes#
public static void Main( string[] args )
{
var procs = Process.GetProcesses().Where( x => x.ProcessName.Contains( "chrome" ) ).ToList();
foreach ( var proc in procs )
{
var timeTotal = DateTime.Now - proc.StartTime;
var timeProc = proc.TotalProcessorTime;
var timeIdle = timeTotal.Subtract( timeProc );
Console.WriteLine( proc.Id + " total " + timeTotal + " user+kernel " + timeProc + " idle " + timeIdle );
}
}
It produces things like:
2570 total 1.18:52:22.8433460 user+kernel 00:48:02 idle 1.18:04:20.843346000:11:57.9100000