dotnet-Snippets.com
Snippets: 73 | Registered User: 84 | Visitors online: 35
Main Menu

Home
Random Snippet
FAQs
Contact Us
Imprint
RSS Feeds

Rss All languages
Rss C#
Rss VB.NET
Rss C++
Rss J#
Rss ASP.NET
Jobs

dotnet Jobs
Google Ads

Sri Lanka .NET 
                Forum Member
Using the Registry

Author: Jan Welker
Programming Language: C# Rating:
not yet rated

Views: 2152

Description:

Create, delete Subkeys and read, write Values to the Registry



C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 // 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;
}

This Snippets could be interesting for you:

Poor Excellent
1 2 3 4 5 6 7 8 9 10
Sign in to vote for this snippet.

Comments:
(Please log in to write an comment.)