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

Retrieves the environment variables for the current process.

Syntax

LPTCH WINAPI GetEnvironmentStrings(void);

Parameters

This function has no parameters.

Return Value

If the function succeeds, the return value is a pointer to the environment block of the current process.

If the function fails, the return value is NULL.

Remarks

The GetEnvironmentStrings function returns a pointer to a block of memory that contains the environment variables of the calling process (both the system and the user environment variables). Each environment block contains the environment variables in the following format:

Var1=Value1\0
Var2=Value2\0
Var3=Value3\0
...
VarN=ValueN\0\0

Treat this memory as read-only; do not modify it directly. To add or change an environment variable, use the GetEnvironmentVariable and SetEnvironmentVariable functions.

When the block returned by GetEnvironmentStrings is no longer needed, it should be freed by calling the FreeEnvironmentStrings function.

Note that the ANSI version of this function, GetEnvironmentStringsA, returns OEM characters.

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 namesGetEnvironmentStringsW (Unicode) and GetEnvironmentStringsA (ANSI)

See Also

Environment Variables
FreeEnvironmentStrings
GetEnvironmentVariable
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
GetEnvironmentStringsA uses the OEM codepage      Gideon7   |   Edit   |  
Note: The "ANSI" version of GetEnvironmentStrings (GetEnvironmentStringsA) returns the strings in the OEM code page, not the ANSI code page. If you need the returned strings in the ANSI code page call the Unicode version (GetEnvironmentStringsW) and translate the returned wide-string to an 8-bit string using a conversion function such as WideCharToMultiByte. Or call GetEnvironmentVariableA, which correctly uses the ANSI code page.
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker