A customer wanted to make a change to a system setting.
We advised them to use the SystemParametersInfo
function, adding
The
SystemParametersInfo
function lets you specify whether you want the change to be permanent or this-session-only.
The customer wrote back,
Were trying to figure out whether there is a way for the settings to only apply for the current user session (e.g. automatically restore itself on the next reboot). Your engineers alluded earlier that this is possible, though looking at the MSDN docs on SetParametersInfo, it seems that both options persist the setting permanently:
- SPIF_
UPDATEINIFILE - Writes the new system-wide parameter setting to the user profile.
- SPIF_
SENDCHANGE - Broadcasts the WM_
SETTINGCHANGE message after updating the user profile.What are we missing?
These two flags control different things.
The SPIF_
message controls
whether the
WM_
message
is sent to all top-level windows to inform them of the change.
It has nothing to do with whether the change is temporary or permanent.
The first flag is the relevant one here.
If you pass the
SPIF_
flag,
then the changes are written to the user profile,
so that they also take effect the next time the user logs on.
Since this customer doesn't want the changes to persist
beyond the current session,
what they want to do is omit the
SPIF_
flag.
Maybe it never occurred to them that they can omit flags.
The customer clarified:
We were wondering if someone could give me more insight into how to accomplish this. We were looking into the SystemParametersInfo MSDN page, specifically at the "UINT fWinIni" parameter. We are not sure what is meant by the update the user profile. Does this mean these settings persist longer than the current user session?
Let me see if I can explain this in words of no more than three syllables.
If you pass the
SPIF_
flag,
then the change is written to the user profile.
This means that the setting takes effect not only
right away but also the next time the user logs on.
If you do not pass the
SPIF_
flag,
then the setting takes effect right away,
but it does not affect what happens the next time
the user logs on.