Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

CreateEnvironmentBlock(,,FALSE) function does not expand REG_EXPAND_SZ type environment variables on Windows Server 2008 R2.


View products that this article applies to.

Symptoms

The CreateEnvironmentBlock function retrieves a block of memory that represents the process environment variables. If the environment block contains environment variables defined in the registry as the REG_EXPAND_SZ type that also contain other REG_EXPAND_SZ environment variables, then these variables may not be fully expanded. For example, if %TEMP% is part of the value of the Path environment variable, it is possible that %TEMP% may not be expanded in the environment block returned by CreateEnvironmentBlock.

This issue does not negatively impact the functioning of Windows in any way. Some applications may not be written to expect this situation and this could result in errors, however.

↑ Back to the top


Cause

This is by design.
It is not guaranteed that the CreateEnvironmentBlock function will fully expand the REG_EXPAND_SZ environment variables that require the expansion of other REG_EXPAND_SZ environment variables. When creating an environment block to return, the system reads through the registry to get the system environment variables. If the REG_EXPAND_SZ variable contains another REG_EXPAND_SZ environment variable whose value has not yet been read in, it will be left unexpanded in the environment block.

For example, if there is a system environment variable AppPath that has not been processed yet, and Path is "%windir%;%AppPath%", it is possible that this will be "C:\Windows;%AppPath%" in the environment block.

↑ Back to the top


Resolution

The CreateEnvironmentBlock function is supposed to retrieve the entire system environment variables as an environment block. An environment block is documented as a null-terminated list of null-terminated strings. The exact content of these strings is not documented, and the intended usage of the environment block is as an argument to CreateProcessAsUser. In order to ensure the full expansion of the environment variables in the block, use the ExpandEnvironmentStrings or ExpandEnvironmentStringsForUser functions.

Environment Variables
http://msdn.microsoft.com/en-us/library/ms682653(VS.85).aspx

ExpandEnvironmentStrings
http://msdn.microsoft.com/en-us/library/ms724265(VS.85).aspx

↑ Back to the top


More Information

Microsoft has confirmed that this is a design in the Microsoft products that are listed in the "Applies to" section. 

↑ Back to the top


Keywords: kb

↑ Back to the top

Article Info
Article ID : 2480007
Revision : 1
Created on : 1/7/2017
Published on : 12/8/2010
Exists online : False
Views : 840