[Win32utils-devel] Question on CreateProcess and handle inheritance

Heesob Park phasis at gmail.com
Wed Sep 2 10:28:36 EDT 2009


2009/9/2 Daniel Berger <djberg96 at gmail.com>:
> Hi,
> I just wanted to make sure that I'm not confused by Michael Buselli's
> comment and patch. As far as I can tell, if you set the bInheritHandle
> in the SECURITY_ATTRIBUTES structure that's passed to CreateProcess to
> true, it's the same as calling SetHandleInformation(handle,
> CreateProcess:
> lpProcessAttributes [in, optional]
>    A pointer to a SECURITY_ATTRIBUTES structure that determines
> whether the returned handle to the new process object can be inherited
> by child processes. If lpProcessAttributes is NULL, the handle cannot
> be inherited.
You must notice that "the returned handle" has nothing to do with the
handle of stdin, stdout, or stderr. The SECURITY_ATTRIBUTES structure
provides security settings for objects created by various functions,
such as CreateFile, CreatePipe, CreateProcess, RegCreateKeyEx, or
RegSaveKeyEx. The returned handle can be a file handle, process handle
or registry handle.

> SetHandleInformation:
>   If this flag is set, a child process created with the
> bInheritHandles parameter of CreateProcess set to TRUE will inherit
> the object handle.
> Or is this a case of "can" (i.e. it's possible for the child to
> inherit the handle) vs "will" (i.e. the child process will definitely
> inherit the handle)?
I guess the child process will definitely inherit the handle when
bInheritHandles flag is set and the handle was not set by
SetHandleInformation(handle,HANDLE_FLAG_INHERIT, 0).

I think  Michael Buselli's patch is acceptable.


Park Heesob

More information about the win32utils-devel mailing list