Tuesday, November 11, 2008

Registry in .NET

Writing:
using Microsoft.Win32;
...
const string REGISTRY_KEY = "software\\yourcompany\\yourapp";
...
RegistryKey key = Registry.CurrentUser.CreateSubKey(REGISTRY_KEY);
key.SetValue("user", args[1]);
key.Close();
Reading:
using Microsoft.Win32;
...
const string REGISTRY_KEY = "software\\yourcompany\\yourapp";
...
string user = null;
RegistryKey key = Registry.CurrentUser.OpenSubKey(REGISTRY_KEY);
if (key != null)
{
user = (string)key.GetValue("user");
key.Close();
}

No comments: