Thread Connection to a Desktop
After a process connects to a window station, the Win32 server assigns a desktop to the thread making the connection to Win32. The desktop assigned during this connection process cannot be closed by calling the CloseDesktop function. The Win32 server determines the desktop to assign to the thread according to the following rules:
-
If the thread has called the SetThreadDesktop function, it connects to the specified desktop.
-
If the thread did not call SetThreadDesktop, it connects to the desktop inherited from the parent process.
-
If the thread did not call SetThreadDesktop and did not inherit a desktop, the Win32 server attempts to open for MAXIMUM_ALLOWED access and connect to a desktop as follows:
-
If a desktop name was specified in the lpDesktop member of the STARTUPINFO structure that was passed to the CreateProcess function when the process was created, the thread connects to the specified desktop.
-
Otherwise, the thread connects to the default desktop of the window station to which the process connected.
The desktop assigned during this connection process cannot be closed by calling the CloseDesktop function.