I am trying to delete the registry Folder using C# code but it throws an exception I.e. key doesn't exists...!!! but if key not exists the how then registry object should be not null But in this case it dnt show it as null it contained some value this my code
bool IsDeleted = false;
try
{
regkey = regkey.Replace(@"HKEY_LOCAL_MACHINE\", "");
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(regkey, true))
{
if (key != null)//here it show that key is exists
{
IsDeleted = DeleteKey(key, regkey);//in this line It generate exception
}
}
}
catch
{
}
return IsDeleted;
this is Delete Code
public static bool DeleteKey(RegistryKey hKey, string strPath)
{
bool flag1 = false;
int num1 = 0;
int num2 = 0;
try
{
num2 = 1;
hKey.DeleteSubKeyTree(strPath);
flag1 = true;
}
catch (Exception obj1) //when (?)
{
Exception exception2 = (Exception)obj1;
Exception exception1 = exception2;
if (num1 == 0)
{
num1 = -1;
switch (num2)
{
case 1:
{
goto Label_0058;
}
}
throw;
}
}
Label_0058:
if (num1 != 0)
{
}
return flag1;
}
please help me for this thnx