There is no automatic way to do this, it has to be explicitly programmed.
In the normal output of the program you record in a file of your choice the data that you think will be necessary in the next activation of the program, and in the activation you read the file and execute the necessary actions according to what was read , for example, change the current application directory.
In order to avoid reinventing the wheel it is possible to use a standard format such as JSON and "ini", but in this case it will be worthwhile to use an external library to read and write the files as there are many of these libraries available.
Alternatively you can use the built-in SQLITE database, but in this case the configuration file will not be in text mode. I think this is an interesting alternative.
Obs. the Windows environment already provides functions ready to access "ini" files. So specifically for Windows it is very easy to use "ini" files.