Source code of Windows XP (NT5)
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.

157 lines
4.8 KiB

  1. #include <windows.h>
  2. #include <winwlx.h>
  3. //
  4. // Some helpful tips about winlogon's notify events
  5. //
  6. // 1) The logoff and shutdown notifications are always done
  7. // synchronously regardless of the Asynchronous registry entry.
  8. //
  9. // 2) If you need to spawn child processes, you have to use
  10. // CreateProcessAsUser() otherwise the process will start
  11. // on winlogon's desktop (not the user's)
  12. //
  13. // 3) The logon notification comes before the user's network
  14. // connections are restored. If you need the user's persisted
  15. // net connections, use the StartShell event.
  16. //
  17. // 4) Don't put any UI up during either screen saver event.
  18. // These events are intended for background processing only.
  19. //
  20. #define NOTIFY_PATH TEXT("Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\\Notify\\notify")
  21. BOOL WINAPI LibMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
  22. {
  23. switch (dwReason)
  24. {
  25. case DLL_PROCESS_ATTACH:
  26. {
  27. DisableThreadLibraryCalls (hInstance);
  28. }
  29. break;
  30. }
  31. return TRUE;
  32. }
  33. VOID WLEventLogon (PWLX_NOTIFICATION_INFO pInfo)
  34. {
  35. OutputDebugString (TEXT("NOTIFY: Entering WLEventLogon.\r\n"));
  36. }
  37. VOID WLEventLogoff (PWLX_NOTIFICATION_INFO pInfo)
  38. {
  39. OutputDebugString (TEXT("NOTIFY: Entering WLEventLogff.\r\n"));
  40. }
  41. VOID WLEventStartup (PWLX_NOTIFICATION_INFO pInfo)
  42. {
  43. OutputDebugString (TEXT("NOTIFY: Entering WLEventStartup.\r\n"));
  44. }
  45. VOID WLEventShutdown (PWLX_NOTIFICATION_INFO pInfo)
  46. {
  47. OutputDebugString (TEXT("NOTIFY: Entering WLEventShutdown.\r\n"));
  48. }
  49. VOID WLEventStartScreenSaver (PWLX_NOTIFICATION_INFO pInfo)
  50. {
  51. OutputDebugString (TEXT("NOTIFY: Entering WLEventStartScreenSaver.\r\n"));
  52. }
  53. VOID WLEventStopScreenSaver (PWLX_NOTIFICATION_INFO pInfo)
  54. {
  55. OutputDebugString (TEXT("NOTIFY: Entering WLEventStopScreenSaver.\r\n"));
  56. }
  57. VOID WLEventLock (PWLX_NOTIFICATION_INFO pInfo)
  58. {
  59. OutputDebugString (TEXT("NOTIFY: Entering WLEventLock.\r\n"));
  60. }
  61. VOID WLEventUnlock (PWLX_NOTIFICATION_INFO pInfo)
  62. {
  63. OutputDebugString (TEXT("NOTIFY: Entering WLEventUnlock.\r\n"));
  64. }
  65. VOID WLEventStartShell (PWLX_NOTIFICATION_INFO pInfo)
  66. {
  67. OutputDebugString (TEXT("NOTIFY: Entering WLEventStartShell.\r\n"));
  68. }
  69. /////////////////////////////////////////////////////////////////////////////
  70. // DllRegisterServer - Adds entries to the system registry
  71. STDAPI DllRegisterServer(void)
  72. {
  73. HKEY hKey;
  74. LONG lResult;
  75. DWORD dwDisp, dwTemp;
  76. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE, NOTIFY_PATH, 0, NULL,
  77. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  78. &hKey, &dwDisp);
  79. if (lResult != ERROR_SUCCESS)
  80. {
  81. return lResult;
  82. }
  83. RegSetValueEx (hKey, TEXT("Logon"), 0, REG_SZ, (LPBYTE)TEXT("WLEventLogon"),
  84. (lstrlen(TEXT("WLEventLogon")) + 1) * sizeof(TCHAR));
  85. RegSetValueEx (hKey, TEXT("Logoff"), 0, REG_SZ, (LPBYTE)TEXT("WLEventLogoff"),
  86. (lstrlen(TEXT("WLEventLogoff")) + 1) * sizeof(TCHAR));
  87. RegSetValueEx (hKey, TEXT("Startup"), 0, REG_SZ, (LPBYTE)TEXT("WLEventStartup"),
  88. (lstrlen(TEXT("WLEventStartup")) + 1) * sizeof(TCHAR));
  89. RegSetValueEx (hKey, TEXT("Shutdown"), 0, REG_SZ, (LPBYTE)TEXT("WLEventShutdown"),
  90. (lstrlen(TEXT("WLEventShutdown")) + 1) * sizeof(TCHAR));
  91. RegSetValueEx (hKey, TEXT("StartScreenSaver"), 0, REG_SZ, (LPBYTE)TEXT("WLEventStartScreenSaver"),
  92. (lstrlen(TEXT("WLEventStartScreenSaver")) + 1) * sizeof(TCHAR));
  93. RegSetValueEx (hKey, TEXT("StopScreenSaver"), 0, REG_SZ, (LPBYTE)TEXT("WLEventStopScreenSaver"),
  94. (lstrlen(TEXT("WLEventStopScreenSaver")) + 1) * sizeof(TCHAR));
  95. RegSetValueEx (hKey, TEXT("Lock"), 0, REG_SZ, (LPBYTE)TEXT("WLEventLock"),
  96. (lstrlen(TEXT("WLEventLock")) + 1) * sizeof(TCHAR));
  97. RegSetValueEx (hKey, TEXT("Unlock"), 0, REG_SZ, (LPBYTE)TEXT("WLEventUnlock"),
  98. (lstrlen(TEXT("WLEventUnlock")) + 1) * sizeof(TCHAR));
  99. RegSetValueEx (hKey, TEXT("StartShell"), 0, REG_SZ, (LPBYTE)TEXT("WLEventStartShell"),
  100. (lstrlen(TEXT("WLEventStartShell")) + 1) * sizeof(TCHAR));
  101. dwTemp = 0;
  102. RegSetValueEx (hKey, TEXT("Impersonate"), 0, REG_DWORD, (LPBYTE)&dwTemp, sizeof(dwTemp));
  103. dwTemp = 1;
  104. RegSetValueEx (hKey, TEXT("Asynchronous"), 0, REG_DWORD, (LPBYTE)&dwTemp, sizeof(dwTemp));
  105. RegSetValueEx (hKey, TEXT("DllName"), 0, REG_EXPAND_SZ, (LPBYTE)TEXT("notify.dll"),
  106. (lstrlen(TEXT("notify.dll")) + 1) * sizeof(TCHAR));
  107. RegCloseKey (hKey);
  108. return S_OK;
  109. }
  110. /////////////////////////////////////////////////////////////////////////////
  111. // DllUnregisterServer - Removes entries from the system registry
  112. STDAPI DllUnregisterServer(void)
  113. {
  114. RegDeleteKey (HKEY_LOCAL_MACHINE, NOTIFY_PATH);
  115. return S_OK;
  116. }