SetEnvironmentVariable
The SetEnvironmentVariable function sets the contents of the specified environment variable for the current process.
Code:
BOOL SetEnvironmentVariable(
LPCTSTR lpName,
LPCTSTR lpValue
);
Parameters
lpName
[in] Pointer to a null-terminated string that specifies 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] Pointer to a null-terminated string that specifies the contents of the environment variable. An environment variable has a maximum size limit of 32,767 bytes, including the trailing null terminator.
If this parameter is NULL, the variable is deleted from the current process's environment.
Return Values
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. For more information, see Environment Variables.
Windows 95/98/Me: SetEnvironmentVariableW is supported by the Microsoft Layer for
Unicode. To use this, you must add certain files to your application, as outlined in Microsoft Layer for
Unicode on Windows 95/98/Me Systems.