SQLite Forum

Setting temp_store_directory on Windows in future proof way
Login
These are C Runtime library functions which do God only knows what (and not even she knows without reading the source code).

Using the SetEnvironmentVariable API does indeed modify the current process environment at the Operating System level as seen by subsequent calls to the GetTempPath API.  The runtime functions do not appear to actually modify the process environment, but rather the runtime library's copy of that environment -- though results may vary depending on the particular implementation, compiler, and runtime.

```
Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec  7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import win32api
>>> import os
>>> os.getenv('TMP')
'C:\\Users\\KMedcalf\\AppData\\Local\\Temp'
>>> win32api.GetTempPath()
'C:\\Users\\KMedcalf\\AppData\\Local\\Temp\\'
>>> win32api.SetEnvironmentVariable('TMP', r'D:\Temp')
>>> os.getenv('TMP')
'C:\\Users\\KMedcalf\\AppData\\Local\\Temp'
>>> win32api.GetTempPath()
'D:\\Temp\\'
>>> ^Z
```