Advertisement
tourniquet

shutdowner

Jan 4th, 2013
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.08 KB | None | 0 0
  1. /*
  2. Version 0.9
  3.  
  4. Usage - shutdowner hh:mm r, where r is restart. r is optional, if you use shutdowner without r, the computer will be shutdown at the selected time.
  5.  
  6. Updated 5 january 2013
  7.  
  8. Author: Ion Prodan
  9.  
  10. */
  11.  
  12. #include <string.h>
  13. #include <stdio.h>
  14. #include <windows.h>
  15. #include <wchar.h>
  16. #include <unistd.h>
  17. #define sleep(x) Sleep(1000 * x)
  18.  
  19. int checkTime();
  20.  
  21. int main ( int argc, char *argv[] ) {
  22.  
  23.     char getCheckTime;
  24.     getCheckTime = 'r';
  25.     char *getFirstArgument = argv[1];
  26.     char *getSecondArgument = argv[2];
  27.  
  28.     checkTime(&getCheckTime);
  29.     //printf( "%s", getCheckTime);
  30.  
  31.     while(*getFirstArgument != getCheckTime) {
  32.         sleep(1);
  33.         checkTime(&getCheckTime);
  34.     }
  35.  
  36.     if(*getSecondArgument == 'r') {
  37.         system("shutdown /r");
  38.     } else {
  39.         system("shutdown /s");
  40.     }
  41.  
  42.     checkTime(getCheckTime);
  43.     printf("%d\n", getCheckTime);
  44.     return 0;  
  45. }
  46.  
  47. int checkTime() {
  48.  
  49.     char getConvertedTime[5] = {};
  50.  
  51.     SYSTEMTIME localTime;
  52.     GetLocalTime ( &localTime );
  53.        
  54.     sprintf( getConvertedTime, "%d:%d", localTime.wHour, localTime.wMinute );
  55.        
  56.     return *getConvertedTime;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement