Free Code Snippets in C#, Net Framework, Office 365, ASP.Net,WPF, Visual Studio, SQL Server, Antivirus free
#


 
error message
When deleting keys in the Windows registry, the error message is output :;

System.UnautohorizedAccessException:
In den Registrierungsschlüssel kann nicht geschrieben werden.

 
The following code creates the error:
The C # code tries to remove a key in the registry

try
{
RegistryKey regKey = Registry.ClassesRoot.OpenSubKey(registry_Menu_Path);
if (regKey != null)
{
if(regKey.SubKeyCount>0)
{
string[] subKeys = regKey.GetSubKeyNames();
foreach (string subKey in subKeys)
{
regKey.DeleteSubKey(subKey);
}
}
}
regKey.Close();
}
catch (Exception ex)
{
WinForms.MessageBox.Show(ex.ToString());
}

 
 

 
 
Solution:
 
You must open the registry key with the writeable attribute writable = true
 
In the code:

RegistryKey regKey = Registry.ClassesRoot.OpenSubKey(registry_Menu_Path,writable:true );
if (regKey != null)
{
//< delete all Subkeys >
if (regKey.SubKeyCount>0)
{
string[] subKeys = regKey.GetSubKeyNames();
foreach (string subKey in subKeys)
{
regKey.DeleteSubKey(subKey);
}
}
//</ delete all Subkeys >
}
regKey.Close();

 
 
Error message:

bei System.ThrowHelper.ThrowUnauthorizedAccessException(ExceptionResource resource)
bei Microsoft.Win32.RegistryKey.EnsureWriteable()
bei Microsoft.Win32.RegistryKey.DeleteSubKey(String subkey, Boolean throwOnMissingSubKey)
bei Microsoft.Win32.RegistryKey.DeleteSubKey(String subkey)
bei Group_Images_By_Date.clsRegistry.fxRegistry_Remove_Key(String registry_Menu_Path) in C:\_Daten\Desktop\WPF\Group_Images_By_Date\Group_Images_By_Date\_classes\clsRegistry.cs:Zeile 63.

 
 
 
 
 
Mobile
»
Error caused by Caliburn Micro
»
WPF: System.Windows.Interactivity is broken or missing
»
WPF Error: An error occurred while signing
»
WPF Registry. DeleteSubKey: System.UnautohorizedAccessException
»
WPF: UserControl.Name does not use hyphen dashes

.

Contact for Jobs, Project Requests: raimund.popp@microsoft-programmierer.de