This article describes performing different-different operations on the Windows registry.
//Create a Particular Registry.
private void btnCreateRegistry_Click(object sender, EventArgs e)
{
RegistryKey RegCreateKey = default(RegistryKey);
RegCreateKey = My.Computer.Registry.CurrentUser.CreateSubKey("ApplicationName\\CompanyName");
}
//Delete a Partucular Registry.
private void btnDeleteRegistry_Click(object sender, EventArgs e)
{
using (RegistryKey RegDeleteKey = My.Computer.Registry.LocalMachine.OpenSubKey("SoftwareName"))
{
RegDeleteKey.DeleteSubKey("KeyToDelete");
}
}
//Read a Particular Registry.
private void btnReadRegistry_Click(object sender, EventArgs e)
{
object RegReadKeyValue = null;
RegReadKeyValue = My.Computer.Registry.GetValue("HKEY_CURRENT_USER\\SoftwareName\\CompanyName\\KeyName", "ValueName", "DefaultValue");
}
//Write a Particular Registry.
private void btnWriteRegistry_Click(object sender, EventArgs e)
{
My.Computer.Registry.SetValue("HKEY_CURRENT_USER\\Software\\CompanyName\\KeyName", "Name", "Value");
}
//Check the registry is exist or not?
private void btnCheckRegistry_Click(object sender, EventArgs e)
{
bool IsRegExists = false;
try
{
//Here it will check the particular given registry.
if (My.Computer.Registry.CurrentUser.OpenSubKey("Software\\Company\\Application\\1.1") != null)
{
//Given registry key is exist...
IsRegExists = true;
}
}
finally
{
My.Computer.Registry.CurrentUser.Close();
}
}