BUG: CreateEnvironmentBlock Fails With Error 203 If the User's Profile Is Not Loaded (305136)



The information in this article applies to:

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

This article was previously published under Q305136

SYMPTOMS

The CreateEnvironmentBlock API will fail if it is used to retrieve environment variables for a user whose profile is not currently loaded. This is by design. However, when this failure occurs, GetLastError() returns error code 203 (ERROR_ENVVAR_NOT_FOUND), which is not a meaningful error under these circumstances.

RESOLUTION

An application should load the user's profile prior to calling CreateEnvironmentBlock. This can be achieved with the LoadUserProfile API. However, this requires administrative privileges. More specifically, LoadUserProfile can only be called by threads running under the LocalSystem account or a local administrator's account.

NOTED EXCEPTIONS

There are some instances in which it is not necessary to call LoadUserProfile to load a user's profile prior to calling CreateEnvironmentBlock. These are as follows:
  • If the user specified by the hToken member of CreateEnvironmentBlock is the interactive user, the user's profile will already be loaded. In this case, it is not necessary to call LoadUserProfile.
  • CreateEnvironmentBlock can be used to retrieve only system environment variables by specifying NULL for the hToken parameter. In this case, the user's profile does not need to be loaded at all.
  • CreateEnvironmentBlock can be used to build an environment block that is identical to the current process's environment block by specifying TRUE for the bInherit parameter. In this case, the user's profile does not have to be loaded at all.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

Modification Type:MajorLast Reviewed:12/18/2003
Keywords:kbAPI kbbug kbKernBase kbRegistry kbSecurity KB305136