Delete Subkey error (C #)

I created the following registry key (copied via regedit):

HKEY_CURRENT_USER \ Software \ Microsoft \ Windows \ CurrentVersion \ test

I would like to delete this registry key, and therefore ... I used the following code and ran a small error.

Reg RegKKey regKey;

    string regPath_Key = @"Software\Microsoft\Windows\CurrentVersion\test";

    regKey = Registry.CurrentUser.OpenSubKey(regPath_Key, true);

    if(regKey != null)   // Always returns null, even though the key does exist.
    {
        Registry.CurrentUser.DeleteSubKey(regPath_Key, true);
    }

The problem I ran into is that the string if(regKey != null)always returns null! I came back and checked that the key does exist several times, but still the same result. Am I going to suggest that my code has problems somewhere?

+3
source share
2 answers

You should not include HKEY_CURRENT_USERin the string passed to Registry.CurrentUser.OpenSubKey(). Use instead

string regPath_Key = @"Software\Microsoft\Windows\CurrentVersion\test";
+1
source

, 64- , x86? , HKCU\Software\Wow6432Node... 32- ...

+2

All Articles