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

Discussion in 'ASP .Net' started by Robert Rotstein, Dec 13, 2005.

  1. 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?
    Robert Rotstein, Dec 13, 2005
    #1
    1. Advertising

  2. Robert Rotstein

    Josh Schultz Guest

    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
    Josh Schultz, Dec 13, 2005
    #2
    1. Advertising

  3. Robert Rotstein

    Bruce Barker Guest

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

    -- bruce (sqlwork.com)


    "Robert Rotstein" <> wrote in message
    news:gwBnf.1417$1b.55@trndny03...
    > 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?
    Bruce Barker, Dec 13, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. HK
    Replies:
    1
    Views:
    3,601
    Cowboy \(Gregory A. Beamer\)
    Apr 1, 2004
  2. bazzer
    Replies:
    0
    Views:
    890
    bazzer
    Mar 24, 2006
  3. Leny
    Replies:
    3
    Views:
    16,900
    Daniel
    Feb 1, 2005
  4. Zubaer Naseem
    Replies:
    1
    Views:
    219
  5. Alexander Pino

    Unable to write to Windows Registry using XML Web Service

    Alexander Pino, May 11, 2004, in forum: ASP .Net Web Services
    Replies:
    2
    Views:
    172
    Ray Deese
    May 11, 2004
Loading...

Share This Page