If you don’t want the changes to be permanent, the don’t pass the flag that says that you want the changes to be permanent

Raymond Chen

A customer wanted to make a change to a system setting. We advised them to use the System­Parameters­Info function, adding

The System­Parameters­Info 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_UPDATE­INI­FILE
Writes the new system-wide parameter setting to the user profile.
SPIF_SEND­CHANGE
Broadcasts the WM_SETTING­CHANGE message after updating the user profile.

What are we missing?

These two flags control different things. The SPIF_SEND­CHANGE message controls whether the WM_SETTING­CHANGE 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_UPDATE­INI­FILE 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_UPDATE­INI­FILE 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 System­Parameters­Info 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 simpler terms.

If you pass the SPIF_UPDATE­INI­FILE 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_UPDATE­INI­FILE flag, then the setting takes effect right away, but it does not affect what happens the next time the user logs on.

0 comments

Discussion is closed.

Feedback usabilla icon