PRB: CreateEnvironmentBlock() Fails If the Environment Block Contains an Empty String (255670)



The information in this article applies to:

  • Microsoft Win32 Application Programming Interface (API), when used with:
    • the operating system: Microsoft Windows NT 4.0

This article was previously published under Q255670

SYMPTOMS

The CreateEnvironmentBlock function fills a block of memory with a list of NULL-terminated strings that represent the environment variables for a specified user. This block is built by using values that are stored in the following registry key:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control
\Session Manager\Environment

If one of the values within this key contains an empty string, CreateEnvironmentBlock will fail. A subsequent call to the GetLastError function incorrectly returns zero (ERROR_SUCCESS).

CAUSE

An empty string is not a valid value for an environment variable. The system was not designed to expect or to handle an empty string value in this key.

RESOLUTION

If CreateEnvironmentBlock returns FALSE and GetLastError returns ERROR_SUCCESS, check the registry key shown in the "Symptoms" section for empty strings. Delete any value that contains an empty string.

STATUS

This behavior is by design.

MORE INFORMATION

On a Microsoft Windows 2000-based computer or later, an empty string value in the environment key does not cause a problem when CreateEnvironmentBlock is called. The system ignores all such values when the environment block is built. Novertheless, an empty string is still not a valid value for an environment variable. Therefore, other unpredictable problems could occur as a result of an empty string value in this key.

Modification Type:MajorLast Reviewed:11/3/2003
Keywords:kbAPI kbKernBase kbprb kbRegistry KB255670