Why SCRNSAVE.EXE value is not updating by code

327 views Asked by At

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");
   }

}

1

There are 1 answers

0
awright18 On BEST ANSWER

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


 }