Description
Proposal
Problem statement
I need a way to customize the STARTUPINFO structure when spawning a new Command
on Windows
Motivating examples or use cases
I'm working on a desktop application which needs to often spawn sub-processes as part of its regular operation. The Command
API works well in general, but there's a problem: by default, on Windows every sub-process causes the parent window to display a "spinner" (aka feedback) cursor until the sub-process displays a window. This becomes problematic when the sub-processes are worker processes that will never display a window, as it makes the parent app appear unresponsive due to the spinning cursor.
In Windows land, this is easily solvable by passing the STARTF_FORCEOFFFEEDBACK
flag to the STARTUPINFO
struct, which is then passed to the CreateProcessW
(see SO question)
Unfortunately, while the Command API exposes a creation_flags
parameter, this only influences the CreateProcessW
flags, not the STARTUPINFO
flags.
Solution sketch
Ideally, the Command API should expose some methods to configure the startupinfo_flags
individually. After a discussion, we propose to expose the following methods:
// Controls STARTF_RUNFULLSCREEN
fn startupinfo_fullscreen(&mut self, enabled: bool)
// Controls STARTF_UNTRUSTEDSOURCE
fn startupinfo_untrusted_source(&mut self, enabled: bool)
// Controls STARTF_FORCEONFEEDBACK and STARTF_FORCEOFFFEEDBACK
fn startupinfo_force_feedback(&mut self, enabled: Option<bool>)
The STARTUPINFO
struct accepts also other flags, but their use is less straightforward as they have side-effects and relationships with other fields, so they can't be changed in isolation (see follow-up comment from @joshtriplett for more details).
Alternatives
For this specific problem, I'm using a workaround to post a dummy message on the sub-process (see SO question). This unfortunately still causes the loading cursor to appear for a fraction of a second, so it's not a solution.
Links and related work
- https://internals.rust-lang.org/t/add-ability-to-customize-startupinfo-structure-in-std-command-api/22569
- https://stackoverflow.com/questions/4942664/avoid-hourglass-after-calling-createprocess
- https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/ns-processthreadsapi-startupinfoa
I believe this would be a great addition to the standard library, as it's similar to the existing creation_flags
argument