Context:
- This question is about how to control, through configuration, whether programmatic cross-process window activation (making a window the foreground window with the input focus) is allowed, via the
SetForegroundWindowWinAPI function.
It seems that the SPI_GETFOREGROUNDLOCKTIMEOUT / SPI_SETFOREGROUNDLOCKTIMEOUT values used with the SystemParametersInfo WinAPI function correspond to the ForegroundLockTimeout persistent, per-user registry value (in HKEY_CURRENT_USER\Control Panel\Desktop).
The foreground-lock timeout is the period of time following interactive user input during which cross-process window activation is not permitted.
My expectation is as follows:
The effective value in a session is the one reported by
SPI_GETFOREGROUNDLOCKTIMEOUT, which may differ from the underlyingForegroundLockTimeoutregistry value if a non-persistent update was made viaSPI_SETFOREGROUNDLOCKTIMEOUT(fWinIniparameter set to0)On next logon, the two values should be back in sync.
This expectation is not met in the following cases:
On Windows 11, the
SPI_GETFOREGROUNDLOCKTIMEOUTalways reports2147483647(the max. value of a signed 32-bit integer) on logon - even though theForegroundLockTimeoutregistry default value is200000Update: The behavior was observed on an ARM W11 ISO image run via the VMWare Fusion Technology Preview for M1 Macs, current as of 16 Sep 2022.
While non-persistent
SPI_SETFOREGROUNDLOCKTIMEOUTupdates are possible, an attempt to persistently change the effectiveSPI_GETFOREGROUNDLOCKTIMEOUTvalue for future session is quietly ignored.In effect, a new user session defaults to not allowing unconditional window activation.
On Windows 10, I observe similar behavior with one particular user account:
The behavior is as on Windows 11, except that
0is the defaultSPI_GETFOREGROUNDLOCKTIMEOUTvalue, which cannot be changed persistently. In effect, a new session for this user default to allowing unconditional window activation.Another user account on the same machine does not exhibit this behavior - there, the above expectations are met.
The machine is not in developer mode; the account with the divergent behavior is an administrator, while the other is not - but I wouldn't expect that to matter.
My questions:
Is the observed Windows 11 behavior to be expected? If so, is it documented somewhere?
On Windows 10, what is the explanation for the behavior of the wayward user account? Is there another persistent setting somewhere that overrides the expected behavior?