Feedback

C# - Using the Registry

Veröffentlicht von am 9/3/2006
(3 Bewertungen)
Create, delete Subkeys and read, write Values to the Registry
 // Create a Subkey
RegistryKey newKey = Registry.CurrentUser.CreateSubKey("SOFTWARE\\SuperSoft\\App");

// Write Values to the Subkey
newKey.SetValue("Value1", "Content1");
newKey.SetValue("Value2", "Content2");

// read Values from the Subkey
if (SubKeyExist("SOFTWARE\\SuperSoft\\App"))
{
	RegistryKey myKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\SuperSoft\\App");
	string firstApp = (string)myKey.GetValue("Value1");
	string secondApp = (string)myKey.GetValue("Value2");
}
else
	throw new Exception("Subkey does not exist!");

// Delete the Subkey
if (SubKeyExist("SOFTWARE\\SuperSoft"))
	Registry.CurrentUser.DeleteSubKeyTree("SOFTWARE\\SuperSoft");
else
	throw new Exception("Subkey does not exist!");
	
	
private bool SubKeyExist(string Subkey)
{
	// Check if a Subkey exist
	RegistryKey myKey = Registry.CurrentUser.OpenSubKey(Subkey);
	if (myKey == null)
		return false;
	else
		return true;
}
Abgelegt unter Subkey, Registry.

Kommentare zum Snippet

 

Logge dich ein, um hier zu kommentieren!