Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.4 KiB

  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <userenv.h>
  4. #include <userenvp.h>
  5. int __cdecl main( int argc, char *argv[])
  6. {
  7. HANDLE hToken;
  8. HANDLE hEventMach, hEventUser, hEvents[2];
  9. DWORD dwRet;
  10. OpenProcessToken (GetCurrentProcess(), TOKEN_ALL_ACCESS, &hToken);
  11. hEvents[0] = hEventMach = CreateEvent (NULL, FALSE, FALSE, TEXT("some event mach"));
  12. hEvents[1] = hEventUser = CreateEvent (NULL, FALSE, FALSE, TEXT("some event user"));
  13. if (!RegisterGPNotification(hEventMach, TRUE)) {
  14. printf("RegisterGPNotification for machine failed with error - %d\n", GetLastError());
  15. return FALSE;
  16. }
  17. if (!RegisterGPNotification(hEventUser, FALSE)) {
  18. printf("RegisterGPNotification for user failed with error - %d\n", GetLastError());
  19. return FALSE;
  20. }
  21. printf("Going into the loop\n");
  22. for (;;) {
  23. dwRet = WaitForMultipleObjects(2, hEvents, FALSE, INFINITE);
  24. switch (dwRet - WAIT_OBJECT_0) {
  25. case 0:
  26. printf("Machine event got notified\n");
  27. break;
  28. case 1:
  29. printf("User event got notified\n");
  30. break;
  31. default:
  32. printf("WaitForMultipleObjects returned error - %d\n", GetLastError());
  33. break;
  34. }
  35. printf("Rewaiting..\n");
  36. }
  37. CloseHandle (hEventMach);
  38. CloseHandle (hEventUser);
  39. return 0;
  40. }