Click to Rate and Give Feedback
MSDN
MSDN Library
Windows Development
System Services
Time
Time Reference
Time Functions
 GetSystemTimes function
GetSystemTimes function

Applies to: desktop apps only

Retrieves system timing information. On a multiprocessor system, the values returned are the sum of the designated times across all processors.

Syntax

BOOL WINAPI GetSystemTimes(
  __out_opt  LPFILETIME lpIdleTime,
  __out_opt  LPFILETIME lpKernelTime,
  __out_opt  LPFILETIME lpUserTime
);

Parameters

lpIdleTime [out, optional]

A pointer to a FILETIME structure that receives the amount of time that the system has been idle.

lpKernelTime [out, optional]

A pointer to a FILETIME structure that receives the amount of time that the system has spent executing in Kernel mode (including all threads in all processes, on all processors). This time value also includes the amount of time the system has been idle.

lpUserTime [out, optional]

A pointer to a FILETIME structure that receives the amount of time that the system has spent executing in User mode (including all threads in all processes, on all processors).

Return value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

To compile an application that uses this function, define _WIN32_WINNT as 0x0501 or later. For more information, see Using the Windows Headers.

Requirements

Minimum supported client

Windows Vista, Windows XP with SP1

Minimum supported server

Windows Server 2003

Header

Winbase.h (include Windows.h)

Library

Kernel32.lib

DLL

Kernel32.dll

See also

FILETIME
System Time
Time Functions

 

 

Send comments about this topic to Microsoft

Build date: 3/6/2012

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Maybe the simplest C# signature      Nico9.1   |   Edit   |   Show History
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool GetSystemTimes(out TimeSpan lpIdleTime, out TimeSpan lpKernelTime, out TimeSpan lpUserTime);
Tags What's this?: Add a tag
Flag as ContentBug
Converting the results to .Net TimeSpan      Negri ... Thomas Lee   |   Edit   |   Show History

You can use this function from .Net by importing with the folowing C#signature:

[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool GetSystemTimes(outFILETIME lpIdleTime, outFILETIME lpKernelTime, outFILETIME lpUserTime);


and then convert the results using the function:

privatestaticTimeSpan GetTimeSpanFromFileTime(FILETIME time)
{
returnTimeSpan.FromMilliseconds((((ulong)time.dwHighDateTime << 32) + (uint)time.dwLowDateTime) / 10000.0);
}
Tags What's this?: .net (x) c# (x) Add a tag
Flag as ContentBug
Processing
© 2012 Microsoft. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker