PWF said:
Hi,
I am writing a WM app where I want to save the settings the user created and
restore them on the next execution.
I would also like the settings to be saved / restored by Activesync.
Any ideas?
I wrote a simple registry class for my purposes which might be of
help:
using Microsoft.Win32;
public class C4BRegistry
{
// The name of the key must include a valid root.
const string app = "MyApp";
const string subkey = "Software\\My Company\\" + app;
RegistryKey regKey, regSubKey;
public void WriteStringValue(string key, string value)
{
regKey = Registry.CurrentUser;
regSubKey = regKey.CreateSubKey(subkey);
regSubKey.SetValue(key, value, RegistryValueKind.String);
}
public void WriteNumericValue(string key, int value)
{
regKey = Registry.CurrentUser;
regSubKey = regKey.CreateSubKey(subkey);
regSubKey.SetValue(key, value, RegistryValueKind.DWord);
}
public string GetStringValue(string key, string def)
{
regKey = Registry.CurrentUser;
regSubKey = regKey.CreateSubKey(subkey);
return regSubKey.GetValue(key, def).ToString();
}
public string[] GetMultipleStringValue(string key)
{
regKey = Registry.CurrentUser;
regSubKey = regKey.CreateSubKey(subkey);
return (string[])regSubKey.GetValue(key, new string[] { "",
"" });
}
public int GetNumericValue(string key, int def)
{
regKey = Registry.CurrentUser;
regSubKey = regKey.CreateSubKey(subkey);
return (int)regSubKey.GetValue(key, def);
}
}
and it is used like this:
// Get settings from Registry
if (oReg.GetStringValue("Device ID", "").Length == 0)
{
oReg.WriteStringValue("Device ID", Did.GetDeviceId);
}
Hope this helps...
Will Chapman