Platform SDK: Group Policy

EnterCriticalPolicySection

The EnterCriticalPolicySection function pauses the background application of policy to allow safe reading of the registry. Applications should use this function if they read multiple policy entries and need to ensure that the values are not changed while they are being read.

HANDLE EnterCriticalPolicySection(
  BOOL bMachine
);

Parameters

bMachine
[in] Specifies whether to stop the application of computer policy or user policy. If this value is TRUE, the system stops applying computer policy. If this value is FALSE, the system stops applying user policy.

Return Values

If the function succeeds, the return value is a handle to a policy section.

If the function fails, the return value is NULL. To get extended error information, call GetLastError.

Remarks

The maximum amount of time an application can hold a critical section is 10 minutes. After 10 minutes, the system releases the critical section and policy can be applied again.

If you need to acquire both the computer and user critical section objects, acquire the user critical section object before acquiring the computer critical section object. This will help prevent a deadlock situation.

To close the handle when you are finished, call the LeaveCriticalPolicySection function. The policy section handle cannot be used in any other Win32 functions.

Requirements

  Windows NT/2000: Requires Windows 2000.
  Header: Declared in Userenv.h.
  Library: Use Userenv.lib.

See Also

Group Policy Overview, Group Policy Functions, LeaveCriticalPolicySection