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.

153 lines
4.5 KiB

  1. #include <windows.h>
  2. #include <userenv.h>
  3. //
  4. // Some helpful tips about group policy extensions
  5. //
  6. // 1) You will be called in the LocalSystem's context
  7. // If you need to access the net, you'll need to impersonate
  8. // the user via the hToken passed in.
  9. //
  10. //
  11. #define GPEXT_PATH TEXT("Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\\GPExtensions\\{febf1208-8aff-11d2-a8a1-00c04fbbcfa2}")
  12. #define GPEXT_NAME TEXT("Group Policy client side extension sample")
  13. BOOL WINAPI LibMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
  14. {
  15. switch (dwReason)
  16. {
  17. case DLL_PROCESS_ATTACH:
  18. {
  19. DisableThreadLibraryCalls (hInstance);
  20. }
  21. break;
  22. }
  23. return TRUE;
  24. }
  25. DWORD ProcessGroupPolicy ( DWORD dwFlags,
  26. HANDLE hToken,
  27. HKEY hKeyRoot,
  28. PGROUP_POLICY_OBJECT pDeletedGPOList,
  29. PGROUP_POLICY_OBJECT pChangedGPOList,
  30. ASYNCCOMPLETIONHANDLE pHandle,
  31. BOOL* pbAbort,
  32. PFNSTATUSMESSAGECALLBACK pStatusCallback )
  33. {
  34. PGROUP_POLICY_OBJECT pCurGPO;
  35. if (dwFlags & GPO_INFO_FLAG_MACHINE)
  36. OutputDebugString (TEXT("GPEXT: Machine GPO\r\n"));
  37. if (dwFlags & GPO_INFO_FLAG_BACKGROUND)
  38. OutputDebugString (TEXT("GPEXT: Background processing of GPO\r\n"));
  39. if (dwFlags & GPO_INFO_FLAG_SLOWLINK)
  40. OutputDebugString (TEXT("GPEXT: Policy is being applied across a slow link.\r\n"));
  41. if (dwFlags & GPO_INFO_FLAG_VERBOSE)
  42. OutputDebugString (TEXT("GPEXT: Verbose policy logging is requested (to the eventlog).\r\n"));
  43. if (dwFlags & GPO_INFO_FLAG_NOCHANGES)
  44. OutputDebugString (TEXT("GPEXT: No changes where detected in this series of GPOs. Policy should be refreshed as quickly as possible.\r\n"));
  45. if (dwFlags & GPO_INFO_FLAG_LINKTRANSITION)
  46. OutputDebugString (TEXT("GPEXT: Link speed transition (either slow to fast or fast to slow)\r\n"));
  47. //
  48. // Process list of deleted GPOs
  49. //
  50. OutputDebugString (TEXT("GPEXT: Processing deleted GPO list\n"));
  51. for (pCurGPO = pDeletedGPOList; pCurGPO; pCurGPO = pCurGPO->pNext)
  52. {
  53. if ( *pbAbort )
  54. {
  55. OutputDebugString (TEXT("GPEXT: Aborting further processing\n"));
  56. break;
  57. }
  58. OutputDebugString (pCurGPO->lpDisplayName);
  59. OutputDebugString (TEXT(" aka "));
  60. OutputDebugString (pCurGPO->szGPOName);
  61. OutputDebugString (TEXT(".\r\n"));
  62. }
  63. //
  64. // Process list of changed GPOs
  65. //
  66. OutputDebugString (TEXT("GPEXT: Processing changed GPO list\n"));
  67. for (pCurGPO = pChangedGPOList; pCurGPO; pCurGPO = pCurGPO->pNext)
  68. {
  69. if ( *pbAbort )
  70. {
  71. OutputDebugString (TEXT("GPEXT: Aborting further processing\n"));
  72. break;
  73. }
  74. OutputDebugString (pCurGPO->lpDisplayName);
  75. OutputDebugString (TEXT(" aka "));
  76. OutputDebugString (pCurGPO->szGPOName);
  77. OutputDebugString (TEXT(".\r\n"));
  78. }
  79. return ERROR_SUCCESS;
  80. }
  81. /////////////////////////////////////////////////////////////////////////////
  82. // DllRegisterServer - Adds entries to the system registry
  83. STDAPI DllRegisterServer(void)
  84. {
  85. HKEY hKey;
  86. LONG lResult;
  87. DWORD dwDisp, dwValue;
  88. lResult = RegCreateKeyEx (HKEY_LOCAL_MACHINE, GPEXT_PATH, 0, NULL,
  89. REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL,
  90. &hKey, &dwDisp);
  91. if (lResult != ERROR_SUCCESS)
  92. {
  93. return lResult;
  94. }
  95. RegSetValueEx (hKey, NULL, 0, REG_SZ, (LPBYTE)GPEXT_NAME,
  96. (lstrlen(GPEXT_NAME) + 1) * sizeof(TCHAR));
  97. RegSetValueEx (hKey, TEXT("ProcessGroupPolicy"), 0, REG_SZ, (LPBYTE)TEXT("ProcessGroupPolicy"),
  98. (lstrlen(TEXT("ProcessGroupPolicy")) + 1) * sizeof(TCHAR));
  99. RegSetValueEx (hKey, TEXT("DllName"), 0, REG_EXPAND_SZ, (LPBYTE)TEXT("gpext.dll"),
  100. (lstrlen(TEXT("gpext.dll")) + 1) * sizeof(TCHAR));
  101. dwValue = 1;
  102. RegSetValueEx (hKey, TEXT("NoGPOListChanges"), 0, REG_DWORD, (LPBYTE)&dwValue,
  103. sizeof(dwValue));
  104. RegCloseKey (hKey);
  105. return S_OK;
  106. }
  107. /////////////////////////////////////////////////////////////////////////////
  108. // DllUnregisterServer - Removes entries from the system registry
  109. STDAPI DllUnregisterServer(void)
  110. {
  111. RegDeleteKey (HKEY_LOCAL_MACHINE, GPEXT_PATH);
  112. return S_OK;
  113. }