DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Solution For A Common Problem: "Cannot Write To The Registry"

05.23.2007
| 4951 views |
  • submit to reddit
        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