-3
FILETIME Kernel_Time;
HANDLE Process = OpenProcess(PROCESS_ALL_ACCESS, FALSE, 0);
GetProcessTimes(Process, NULL, NULL, &Kernel_Time, NULL);
SYSTEMTIME Sys_Time;
FileTimeToSystemTime(&Kernel_Time, &Sys_Time);
printf("%d", Sys_Time.wYear); // WHY ?

Why Sys_Time.wYear is not 2013?

Could anyone help me?

hello_there_andy
  • 2,039
  • 2
  • 21
  • 51
Kevin Dong
  • 5,001
  • 9
  • 29
  • 62
  • 1
    Hey, why are posting the same question again and again. http://stackoverflow.com/questions/20033457/problems-in-getting-process-time-in-c-please-help-me – Abhineet Nov 18 '13 at 06:32
  • Even if your code *would work*: Do you really expect the System Process to be running for 2013 years? I don't think that Windows computers existed 2013 years ago... – Martin R Nov 18 '13 at 07:35
  • But answer is same. ;-) – Xearinox Nov 18 '13 at 07:36
  • @Martin R The reason I use `Sys_Time.wYear` is to check whether this code work or not. – Kevin Dong Nov 18 '13 at 09:15

1 Answers1

4
HANDLE Process = OpenProcess(PROCESS_ALL_ACCESS, FALSE, 0);

As per the documentation,

If the specified process is the System Process (0x00000000), the function fails and the last error code is ERROR_INVALID_PARAMETER.

So, your OpenProcess fails with ERROR_INVALID_PARAMETER, and the HANDLE Process is NULL. Always check for the Failure conditions and respective Error Codes.

Then again, GetProcessTimes API parameters are not optional, so you should not be passing NULL to them instead of pointer to FILETIME structures.

Abhineet
  • 5,320
  • 1
  • 25
  • 43