Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2005
Visual Studio
Samples
Technology Samples
 RegistrySettingsProvider Sample

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
.NET Framework Samples 
RegistrySettingsProvider Sample 

Download sample

This sample demonstrates how to persist application settings in the registry.

For information about using the samples, see the following topics:

Caution noteCaution

This provider uses assembly metadata, such as product name, to determine a workable registry path in which to store settings. These are not secure metadata elements; they are reasonably safe from collision, but not at all safe from malicious tampering. A robust implementation of the provider, meant for use in a production environment, should improve upon this pathing algorithm.

Security noteSecurity Note

This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.

To build and run the sample using the command prompt

  1. At the command prompt, navigate to the location where you saved the uncompressed sample files.

  2. Navigate to one of the language-specific subdirectories under the RegistrySettingsProvider directory.

  3. Type msbuild to build the sample using the solution (.sln) file provided.

  4. Type cd RegistrySettingsProvider\bin\Debug to navigate to the location of the executable file.

  5. Type RegistrySettingsProvider.exe to run the sample.

To build and run the sample using Visual Studio

  1. In Windows Explorer, navigate to the location where you saved the uncompressed sample files.

  2. Navigate to one of the language-specific subdirectories under the RegistrySettingsProvider directory.

  3. Double-click the solution (.sln) file to open it in Visual Studio.

  4. In Visual Studio, press F5 to build and run the sample.

Demonstrates

See Also

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
RegistrySettingsProvider Sample Fix      mj1ab ... Thomas Lee   |   Edit   |   Show History
This is a good sample, but it needs one small fix. The example code does not use a VS created Settings class, but being able to use the designer (Settings.Designer.cs + Settings.cs) with this custom SettingsProvider is very useful. If you are using a VS Settings designer created class, the current implementation will ignore default values (from DefaultSettingValueAttribute). This can be solved by changing the GetPropertyValues() method line:

value.SerializedValue = GetRegKey(setting).GetValue(setting.Name);
to
value.SerializedValue = GetRegKey(setting).GetValue(setting.Name, setting.DefaultValue);

If the registry entry does not exist the settings default value will be returned. This is the desired behavior.

Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker