====== Writing an Environment Variable ====== The function to write an environment variable is [[https://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/setenvironmentvariable.asp|SetEnvironmentVariable()]]. The code below will create an environment variable called DataPath, representing the path to the application's data. The function will set it to C:\Data\. Paste the code below in the [[CLICK_event|CLICK Event]] of a button in a window: declare function SetEnvironmentVariable key = 'DataPath' value = 'C:\Data\' rv = SetEnvironmentVariable ( key , value) The values of the key and value are, of course, known before the call, so there is no need to predetermine the buffer size. Only one call is necessary. === The Windows API Declaration === The code above will not run until the declaration for [[https://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/setenvironmentvariable.asp|SetEnvironmentVariable()]] has been added. To add the declarations, do the following: * Log out of the application. * Log into the SYSPROG application. * Add a row, (call it DLL_APICALLS_KERNEL32), with the first line as KERNEL32 and containing the declarations as shown below. KERNEL32 LONG STDCALL SetEnvironmentVariableA(LPCHAR, LPCHAR) As SetEnvironmentVariable //....add any other declarations in KERNEL32 here..... The function is aliased to its the ANSI version SetEnvironmentVariableA(). * Save the row. * Run [[declare_FCNS|Declare_FCNS]] at the System Editor Exec Line to create the declaration header, as shown below: RUN DECLARE_FCNS 'DLL_APICALLS_KERNEL32' * Exit the editor. * Log out of SYSPROG. * Log into your application. * Run the window.