Share via


Registering a Policy Callback Function

The system calls registered policy callback functions to apply policy. The following code example shows how to register the application-defined callback function ProcessGroupPolicy. 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 CALLBACK ProcessGroupPolicy( 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,
                              &amp;hKey,
                              &amp;dwDisp);

    if( lResult != ERROR_SUCCESS ) return lResult;

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

    RegSetValueEx( hKey,
                   "ProcessGroupPolicy",
                   0,
                   REG_SZ,
                   "ProcessGroupPolicy",
                   lstrlen("ProcessGroupPolicy") + 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;
}