Saturday, May 30, 2009

Solution for a common problem: "Cannot write to the registry"

// Solution for a common problem: "Cannot write to the registry"

// Original (not working):

RegistryKey reg = Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop");
reg.SetValue("WallpaperStyle", "1"); //2 for stretch


// Modified (working):

RegistryKey reg = Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop", true);
reg.SetValue("WallpaperStyle", "1"); //2 for stretch

No comments:

Post a Comment