Unable to delete a registry key from an ASP.NET web service

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?
 
J

Josh Schultz

I wouldn't expect either operation to be successful... I'd assume that
the service runs under the ASPNET user, which shouldn't have
permissions to alter the registry.

(YMMV, I guess)

-j
 
B

Bruce Barker

because asp.net is a service, there is no current user (profile)

-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top