Export (0) Print
Expand All
Expand Minimize

SetEnvironmentVariable function

Sets the contents of the specified environment variable for the current process.

Syntax


BOOL WINAPI SetEnvironmentVariable(
  _In_      LPCTSTR lpName,
  _In_opt_  LPCTSTR lpValue
);

Parameters

lpName [in]

The name of the environment variable. The operating system creates the environment variable if it does not exist and lpValue is not NULL.

lpValue [in, optional]

The contents of the environment variable. The maximum size of a user-defined environment variable is 32,767 characters. For more information, see Environment Variables.

Windows Server 2003 and Windows XP:  The total size of the environment block for a process may not exceed 32,767 characters.

If this parameter is NULL, the variable is deleted from the current process's environment.

Return value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

This function has no effect on the system environment variables or the environment variables of other processes.

Examples

For an example, see Changing Environment Variables.

Requirements

Minimum supported client

Windows XP [desktop apps only]

Minimum supported server

Windows Server 2003 [desktop apps only]

Header

WinBase.h on Windows XP, Windows Server 2003, Windows Vista, Windows 7, Windows Server 2008, and Windows Server 2008 R2 (include Windows.h);
Processenv.h on Windows 8 and Windows Server 2012

Library

Kernel32.lib

DLL

Kernel32.dll

Unicode and ANSI names

SetEnvironmentVariableW (Unicode) and SetEnvironmentVariableA (ANSI)

See also

Environment Variables
GetEnvironmentVariable

 

 

Community Additions

ADD
Show:
© 2014 Microsoft