Platform SDK: Group Policy |
When implementing policy for your application, you must decide which policy events to handle. The policy data type will often determine which events your application handles.
If your application uses registry-based policy settings, it should read them only when the user starts the application. Applying policy while your application is in use can cause problems for the user.
Use caution when reading policy information from the registry. Another application can update policy while your application is reading the registry. To ensure that policy is not updated while you are reading the registry, call the EnterCriticalPolicySection function to obtain ownership of the policy section. When you have finished reading the registry, call the LeaveCriticalPolicySection function to release ownership of the policy section, so other applications can resume updating policy. If the policy section is not released within 10 minutes, the system will release the policy section.
If your application uses file-based policy settings, you must provide a ProcessGroupPolicyProc callback function. The system calls all registered callback functions when applying policy. To register the callback function, create a subkey under the following registry key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\GPExtensions
The name of the subkey must be a GUID. For more information, see Creating a Policy Callback Function.
Services should read policy at service start. When the service must reread the policy settings, it calls GetGPOList to retrieve the list of GPOs.
An application, snap-in extension, or service can monitor changes that take place in policy and apply policy accordingly. The system broadcasts the WM_SETTINGCHANGE message to all desktops when policy has changed. The lParam parameter points to the string "Policy". The wParam parameter is 1 if computer policy was applied or zero if user policy was applied.
Snap-in extensions and applications that do not have a window to receive messages can use the RegisterGPNotification function to receive notification when there is a change in policy.