Home All Groups Group Topic Archive Search About

AGAIN: updating the registry without rebooting the operating system

Author
9 Aug 2006 11:52 PM
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.

Author
10 Aug 2006 4:37 AM
Carl Daniel [VC++ MVP]
Anil Bakirci wrote:
> 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
Author
10 Aug 2006 9:59 AM
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)

Show quote
"Carl Daniel [VC++ MVP]" <cpdaniel_remove_this_and_nospam@mvps.org.nospam>
wrote in message news:O93fmaDvGHA.4456@TK2MSFTNGP06.phx.gbl...
> Anil Bakirci wrote:
>> 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
>
>
>
>
Author
10 Aug 2006 2:46 PM
Carl Daniel [VC++ MVP]
Anil Bakirci wrote:
> 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
Author
10 Aug 2006 10:57 AM
Anil Bakirci
perhaps i have to refresh the desktop, how is that programmatically possible
?

Show quote
"Carl Daniel [VC++ MVP]" <cpdaniel_remove_this_and_nospam@mvps.org.nospam>
wrote in message news:O93fmaDvGHA.4456@TK2MSFTNGP06.phx.gbl...
> Anil Bakirci wrote:
>> 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
>
>
>
>
Author
10 Aug 2006 3:06 PM
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.

AddThis Social Bookmark Button