Why SCRNSAVE.EXE value is not updating by code
-
14-07-2021 - |
Question
I want to update "SCRNSAVE.EXE" value using my c# sample code..
But its doesnt allowing me to do so..!!
Can any one help me on this, below is the function that i am using to update value.
private void setAsDefaultScreenSaver(string valuePath)
{
RegistryKey key = Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop");
if (key == null)
return;
else
{
key.SetValue("SCRNSAVE.EXE", valuePath);
key.SetValue("ScreenSaveActive", "1");
}
}
Solution
You are opening the subkey as read-only. You need to pass in true as the second param to write to it.
private void setAsDefaultScreenSaver(string valuePath)
{
RegistryKey key = Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop",true);
if (key == null)
return;
else
{
key.SetValue("SCRNSAVE.EXE", valuePath);
key.SetValue("ScreenSaveActive", "1");
}
key.Close(); //close the key and flush it to disk
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow