In what structure does Windows keep data about what is the working directory (or the current directory) of the process?

StackOverflow https://stackoverflow.com/questions/16210027

Question

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:

working directory-explicit-implicit-Windows

  • Through the command line, I only pass the location of the script directory (~as the zeroth parameter). Note that the script directory is not the working directory.

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.

Was it helpful?

Solution

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).

CreateProcess

That parameter is later stored in the undocumented property of the RTL_USER_PROCESS_PARAMETERS structure. msdnLink, docLink

  • note the word: undocumented (that's why I haven't found the info on msdn in the first place).

enter image description here

Related stackoverflow questions:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top