While reading on what the working directory and what the script directory (or the directory that contains the image of the executable file) directories are, I started wondering, how does Windows know, what directory to pass to the process as the working directory, when I actually don't specify the working directory when I launch a given program:
I know that I can use GetCurrentDir() to retrieve the working directory inside of the program, but I'm wondering, does Windows have any 'internal' structure that stores the working directory of a given process? (and if yes, is there any documentation on that structure).
I've found out the following process related structures, but it appears none of them contains the working directory property.
The shell (or the program that launches the script), calls the CreateProcess()
function. The CreateProcess function has the lpCurrentDirectory
parameter. The shell (or any other program that launches the script), sets the lpCurrentDirectory
parameter implicitly (~not through the parameters of the script).
That parameter is later stored in the undocumented property of the RTL_USER_PROCESS_PARAMETERS
structure. msdnLink, docLink
Related stackoverflow questions: