R
Robert Rotstein
I’m running an ASP.NET web service which dynamically creates a registry
key, stores some values in it, then, on a subsequent call to another
method in the service, attempts to delete the key. The problem is, the
delete operation always fails with the error message “Cannot write to
the registry key”. The program tries to create the key under
HKEY_CURRENT_USER\some_name\<some GUID value>, but for some reason, it
gets created instead under HKEY_USERS\.DEFAULT\some_name\<some GUID
value>. That doesn’t particularly bother me, though I am curious to
know why the key gets created there instead. But what does bother me is
that the service fails to delete the key and throws an exception. Does
it have anything to do with the stateless nature of the web service, and
that the delete is being attempted on a different thread from the one
that created it? In any case, this statement:
RegistryKey key = RegMainKey.OpenSubKey(guidKey.ToString());
works correctly, but this one:
RegMainKey.DeleteSubKeyTree(guidKey.ToString());
raises the exception. Why? How do I get around it?
key, stores some values in it, then, on a subsequent call to another
method in the service, attempts to delete the key. The problem is, the
delete operation always fails with the error message “Cannot write to
the registry key”. The program tries to create the key under
HKEY_CURRENT_USER\some_name\<some GUID value>, but for some reason, it
gets created instead under HKEY_USERS\.DEFAULT\some_name\<some GUID
value>. That doesn’t particularly bother me, though I am curious to
know why the key gets created there instead. But what does bother me is
that the service fails to delete the key and throws an exception. Does
it have anything to do with the stateless nature of the web service, and
that the delete is being attempted on a different thread from the one
that created it? In any case, this statement:
RegistryKey key = RegMainKey.OpenSubKey(guidKey.ToString());
works correctly, but this one:
RegMainKey.DeleteSubKeyTree(guidKey.ToString());
raises the exception. Why? How do I get around it?