Pastebin

Paste #667: No description

< previous paste - next paste>

Pasted by Anonymous Coward

Download View as text

/*
 * Description: Displays how long Windows has run.
 *
 * Author: Thomas Damgaard Nielsen [spam at thomasdamgaard dot dk]
 * 
 * Dependencies: Kernel32.dll.
 * 
 * Should work on:
 *   Windows Vista, Windows XP, Windows 2000 Professional, 
 *   Windows NT Workstation, Windows Me, Windows 98, Windows 95,
 *   Windows Server "Longhorn", Windows Server 2003, 
 *   Windows 2000 Server, and Windows NT Server.
 *
 * WARNING: Systemuptime from GetTickCount() will overflow and wrap 
 * around to zero if the system is run continuously for 49.7 days.
 */
#include <Windows.h>
#include <Winbase.h>
#include <stdio.h>
#define plural(x)  x, (x == 1 ? "" : "s")

int main() {
  unsigned int days, hours, minutes, seconds;
  DWORD dwUptime = GetTickCount();
  dwUptime = dwUptime / 1000;

  days = dwUptime / 86400;
  dwUptime = dwUptime - (days * 86400);
  
  hours = dwUptime / 3600;
  dwUptime = dwUptime - (hours * 3600);

  minutes = dwUptime / 60;

  seconds = dwUptime - (minutes*60);
  if(days) {
    printf("System uptime: %d day%s, %d hour%s, %d minute%s, %d second%s\n",
            plural(days), plural(hours), 
            plural(minutes), plural(seconds));
  } else if (hours) {
    printf("System uptime: %d hour%s, %d minute%s, %d second%s\n",
            plural(hours), plural(minutes), 
            plural(seconds));
  } else if (minutes) {
    printf("System uptime: %d minute%s, %d second%s\n",
            plural(minutes), plural(seconds));
  } else {
    printf("System uptime: %d second%s\n",
            plural(seconds));
  }

  return 0;

}

New Paste


Do not write anything in this field if you're a human.

Go to most recent paste.