PC Review


Reply
Thread Tools Rate Thread

AGAIN: updating the registry without rebooting the operating system

 
 
Anil Bakirci
Guest
Posts: n/a
 
      10th Aug 2006
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.


 
Reply With Quote
 
 
 
 
Carl Daniel [VC++ MVP]
Guest
Posts: n/a
 
      10th Aug 2006
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...asp?frame=true

-cd



 
Reply With Quote
 
Anil Bakirci
Guest
Posts: n/a
 
      10th Aug 2006
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)

"Carl Daniel [VC++ MVP]" <(E-Mail Removed)>
wrote in message news:(E-Mail Removed)...
> 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...asp?frame=true
>
> -cd
>
>
>
>



 
Reply With Quote
 
Anil Bakirci
Guest
Posts: n/a
 
      10th Aug 2006
perhaps i have to refresh the desktop, how is that programmatically possible
?

"Carl Daniel [VC++ MVP]" <(E-Mail Removed)>
wrote in message news:(E-Mail Removed)...
> 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...asp?frame=true
>
> -cd
>
>
>
>



 
Reply With Quote
 
Carl Daniel [VC++ MVP]
Guest
Posts: n/a
 
      10th Aug 2006
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


 
Reply With Quote
 
hSiplu
Guest
Posts: n/a
 
      10th Aug 2006
> 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference in Registry Setting for different Operating System Shekar Microsoft Windows 2000 Registry Archive 1 6th Oct 2004 12:53 PM
Difference in Registry Setting for different Operating System Shekar Microsoft Windows 2000 Registry 1 6th Oct 2004 12:53 PM
updating the system registry Doug Windows XP Security 1 9th Jan 2004 12:45 AM
Re: Updating System Registry Mark V Microsoft Windows 2000 Registry Archive 0 11th Dec 2003 02:40 PM
Re: Updating System Registry Mark V Microsoft Windows 2000 Registry Archive 0 11th Dec 2003 02:40 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:47 AM.