Platform SDK: Group Policy

Registering a Policy Callback Function

The system calls registered policy callback functions so they can apply policy. The following example registers a callback function named ProcessGroupPolicyProc. This function is implemented in a DLL named gpext.dll.

#include <windows.h>

#define GPEXT_PATH "Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\\GPExtensions\\{MYGUID}"

// Prototype of callback function.

DWORD ProcessGroupPolicyProc( DWORD, HANDLE, HKEY, PGROUP_POLICY_OBJECT, PGROUP_POLICY_OBJECT, ASYNCCOMPLETIONHANDLE, BOOL *, PFNSTATUSMESSAGECALLBACK );

// Registers the callback function.

STDAPI DllRegisterServer(void)
{
    HKEY hKey;
    LONG lResult;
    DWORD dwDisp;

    // Create the key described in GPEXT_PATH.

    lResult = RegCreateKeyEx( HKEY_LOCAL_MACHINE,
                              GPEXT_PATH,
                              0,
                              NULL,
                              REG_OPTION_NON_VOLATILE,
                              KEY_WRITE,
                              NULL,
                              &hKey,
                              &dwDisp);

    if( lResult != ERROR_SUCCESS ) return lResult;

    // Store ProcessGroupPolicyProc as the name of the callback 
    // function.

    RegSetValueEx( hKey,
                   "ProcessGroupPolicy",
                   0,
                   REG_SZ,
                   "ProcessGroupPolicyProc",
                   lstrlen("ProcessGroupPolicyProc") + 1 );

    // Store gpext.dll as the name of the DLL that contains the 
    // callback function.

    RegSetValueEx( hKey,
                   "DllName",
                   0,
                   REG_EXPAND_SZ,
                   "gpext.dll",
                   lstrlen("gpext.dll") + 1 );

    // Close the registry key.

    RegCloseKey( hKey );

    return S_OK;
}