AGAIN: updating the registry without rebooting the operating system

A

Anil Bakirci

How is this possible ?

Some control panel items provide an apply button that instantly resets the
registry change and continue with the changed settings.

Here is the example :

right click on the desktop -> (display)properties ->desktop
than if i select any color (let's assume black) and click on the apply
button; i get a window "Please Wait, the reg key "HKEY_CURRENT_USER /
ControlPanel / Colors / Background" is set to dec-value 0 0 0 and i get a
black backgorund.

But if change the regkey manually with registry editor to 0 0 0 or with
external c#-Function SetValue, the regkey is set to 0 0 0 but it does not
take effect, in other words i dont get a black background.

I tried this :

static class SafeNativeMethods
{
public static IntPtr HWND_BROADCAST = (IntPtr)0xffff;
public static int WM_WININICHANGE = 0x001A;

[DllImport("User32.Dll")]
public static extern bool PostMessage(IntPtr hWnd, int Msg, int wParam, int
lParam);
}

public static class Refresher
{
public static void ReloadSettings()
{
SafeNativeMethods.PostMessage(SafeNativeMethods.HWND_BROADCAST,
SafeNativeMethods.WM_WININICHANGE, 0, 5000);
}
}

static void ExWin()
{
Form form = new Form();
Refresher.ReloadSettings();
Application.Run(form);
}

But it also didnt work. So what's the trick, that Windows updates/refreshes
the registry, when i click the apply button ? For those, who say that it is
only possible for the operating system :
There are several softwares on the market, which play with the registry
settings and do not force the user to restart the PC.
Actually, what i'm currently tring to write is a likely windows tweaker.
 
C

Carl Daniel [VC++ MVP]

Anil said:
Here is the example :
public static class Refresher
{
public static void ReloadSettings()
{
SafeNativeMethods.PostMessage(SafeNativeMethods.HWND_BROADCAST,
SafeNativeMethods.WM_WININICHANGE, 0, 5000);
}
}

The message you need to post is WM_SETTINGCHANGE

In C++:

SendMessageTimeout(
HWND_BROADCAST,
WM_SETTINGCHANGE,
0,
(LPARAM) "Environment",
SMTO_ABORTIFHUNG,
5000,
&dwReturnValue
);

See
http://msdn.microsoft.com/library/en-us/sysinfo/base/wm_settingchange.asp?frame=true

-cd
 
A

Anil Bakirci

WM_SETTINGCHANGE and WM_WININICHANGE are the same messages.
However although if i use SendMessageTimeout as u wrote, it does not work,
the registry is not updated.
(by the way if i send for example a WM_CLOSE all programs are cloesd, so
SendMessageTimeout works but it does not effect the registry)
 
A

Anil Bakirci

perhaps i have to refresh the desktop, how is that programmatically possible
?
 
C

Carl Daniel [VC++ MVP]

Anil said:
WM_SETTINGCHANGE and WM_WININICHANGE are the same messages.
However although if i use SendMessageTimeout as u wrote, it does not
work, the registry is not updated.

The registry is completely unaffected by WM_SETTINGCHANGE - the only effect
of that message is to inform applications (including Explorer) that they
should re-read the registry values.
(by the way if i send for example a WM_CLOSE all programs are cloesd,
so SendMessageTimeout works but it does not effect the registry)

Of course it doesn't. Only writing to the registry affects the registry.

There must be something wrong with code you're not showing, because
broadcasting WM_SETTINGCHAGE is THE ONLY way to get the shell to reflect
changes to the UI settings without rebooting (or logging off and back on in
some cases).

-cd
 
H

hSiplu

right click on the desktop -> (display)properties ->desktop
than if i select any color (let's assume black) and click on the apply
button; i get a window "Please Wait, the reg key "HKEY_CURRENT_USER /
ControlPanel / Colors / Background" is set to dec-value 0 0 0 and i get a
black backgorund.

But if change the regkey manually with registry editor to 0 0 0 or with
external c#-Function SetValue, the regkey is set to 0 0 0 but it does not
take effect, in other words i dont get a black background.

I am not expert. but i can tell you, logging off the current session
and then loggin in will apply the settings. and you don't have to
restart the machine. it should your problem.
programmatically logging off is your part now.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top