Win32/SCM: Is there a supported way to enforce an exact service environment before any service loader/runtime execution?

Nico Messerlian 0 Reputation points
2026-09-13T02:51:24.2966667+00:00

I am evaluating a native Win32 service where the initial process environment must be explicitly specified and validated before any environment-dependent loader/runtime execution occurs.

StartServiceW does not expose an environment argument. In the path I am evaluating, failure of the mechanism that constructs the service environment can ultimately result in process creation with a null environment pointer, causing inheritance from the parent.

Is there a documented, supported Windows mechanism that guarantees all of the following for the initial service process:

an explicitly specified/approved environment is used;

failure to construct that environment, null output, or mismatch fails closed before affected process execution;

the guarantee begins before loader/CRT/runtime initialization can consume that environment?

If such a mechanism exists, what API/configuration provides it and where is its contract documented?

If SCM does not provide this guarantee, is that an intentional limitation of the supported service-start contract?

I am specifically asking about the initial service process, not a service subsequently creating a child with an explicit environment.

Windows development | Windows API - Win32

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.