Click to Rate and Give Feedback
MSDN
MSDN Library
System Services
 GetEnvironmentVariable Function
GetEnvironmentVariable Function

Retrieves the contents of the specified variable from the environment block of the calling process.

Syntax

DWORD WINAPI GetEnvironmentVariable(
  __in_opt   LPCTSTR lpName,
  __out_opt  LPTSTR lpBuffer,
  __in       DWORD nSize
);

Parameters

lpName [in, optional]

The name of the environment variable.

lpBuffer [out, optional]

A pointer to a buffer that receives the contents of the specified environment variable as a null-terminated string. An environment variable has a maximum size limit of 32,767 characters, including the null-terminating character.

nSize [in]

The size of the buffer pointed to by the lpBuffer parameter, in characters.

Return Value

If the function succeeds, the return value is the number of characters stored in the buffer pointed to by lpBuffer, not including the terminating null character.

If lpBuffer is not large enough to hold the data, the return value is the buffer size, in characters, required to hold the string and its terminating null character.

If the function fails, the return value is zero. If the specified environment variable was not found in the environment block, GetLastError returns ERROR_ENVVAR_NOT_FOUND.

Remarks

This function can retrieve either a system environment variable or a user environment variable.

Examples

For an example, see Changing Environment Variables.

Requirements

Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWinbase.h (include Windows.h)
LibraryKernel32.lib
DLLKernel32.dll
Unicode and ANSI namesGetEnvironmentVariableW (Unicode) and GetEnvironmentVariableA (ANSI)

See Also

Environment Variables
GetEnvironmentStrings
SetEnvironmentVariable


Send comments about this topic to Microsoft

Build date: 11/6/2008

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker