Reputation: 622
I am trying to make a application that can change registry values. I Can Change registry Values well but problem is need a restart to get it`s effect. I want to do it without restart.
I want change OS registry Value like as wallpaper and others.
Upvotes: 2
Views: 15638
Reputation: 118
Like many people have replied, some apps will only read a specific registry key once, so changing it will not have effect until that application is restarted. However, many windows registry settings can have their effects applied by broadcasting a notification of a settings change.
Hopefully this can be of some help to others who come to this thread.
[DllImport("user32.DLL")]
public static extern bool SendNotifyMessageA(IntPtr hWnd, uint Msg, int wParam, int lParam);
public static IntPtr HWND_BROADCAST = (IntPtr)0xffff;
public static uint WM_SETTINGCHANGE = 0x001A;
private static void ApplyRegistryChanges()
{
SendNotifyMessageA(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0);
}
Upvotes: 1
Reputation: 86729
Registry changes already take effect immediately, however many applications (and some operating system components) only read registry settings once when they first start, so the registry changes won't have any effect until the application / machine is restarted.
If you are responsible for maintaining an application that uses registry settings and you want your application to respond to registry changes immediately without needing to be restarted then you can use the WMI to recieve notifications when the registry is modified. See Registry Watcher C#
If you are attempting to update a registry key for another application (or operating system component) and want the changes to take effect immediately then this is down to the specific application - be aware that there probably isn't a whole load that you can do unless this is already supported by that application, or you can persuade the application maintainers to modify the application for you.
Update: If you are attempting to update OS settings like the wallpaper then usually the registry is the wrong place to look! As well as the problems you are currently facing you will probably find that the registry keys will change in future versions of Windows, breaking your application.
Instead you should use the defined Windows APIs to do these sorts of things, for example the SystemParametersInfo function can be used to update the wallpaper, see Wallpaper in c#:
For setting a wallpaper you can use SystemParametersInfo to set a wallpaper image programmaticly. This works for Bitmap's only, so when you want to set a other image-format you must first convert this to a Bitmap image.
[DllImport("user32.dll", CharSet = CharSet.Auto)] private static extern Int32 SystemParametersInfo(UInt32 uiAction, UInt32 uiParam, String pvParam, UInt32 fWinIni); private static UInt32 SPI_SETDESKWALLPAPER = 20; private static UInt32 SPIF_UPDATEINIFILE = 0x1; private String imageFileName = "c:\\sample.bmp"; public void SetImage( string filename ) { SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, filename, SPIF_UPDATEINIFILE); }
Upvotes: 8
Reputation: 24847
Shut down and restart all apps/services that read your registry key/s when started. If an app/whatever reads a key at startup and never again, (like most of them), I cannot see any other way of propagating your change.
Get ready for a lot of UAC popups...
Rgds, Martin
Upvotes: 1
Reputation: 8347
I suppose it does depend on the effect. The registry value gets changed immediately, but the reboot forces all programs to reload their registry values.
Upvotes: 1
Reputation: 37172
Registry changes will take immediate effect unless your application has cached the setting. In this case, you have 2 options:
Upvotes: 2