MSDOTnet.org Forum Index
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

RegistryKey.DeleteSubKeyTree throws an UnathorizedAccessExce

 
Post new topic   Reply to topic    MSDOTnet.org Forum Index -> Security
Author Message
Dmitry Shaporenkov



Joined: 08 Aug 2007
Posts: 3

PostPosted: Sat Sep 13, 2003 9:15 am    Post subject: RegistryKey.DeleteSubKeyTree throws an UnathorizedAccessExce Reply with quote

Hi all,

I know this topis was already discussed in the newsgroup,
but I can't find any conclusions. The problem is that
when I try to use RegistryKey.DeleteSubKeyTree, it throws
an UnauthorizedAccessException. I'am a local
administrator on my machine, and the .NET framework
configuration has not been changed since install time.
The code snippet is as follows:
.....
RegistryKey CLSIDKey = Registry.ClassesRoot.OpenSubKey
("CLSID");
try
{
RegistryPermission regPerm = new RegistryPermission
(RegistryPermissionAccess.Write, CLSIDKey.Name + "\\" +
ourGUID);
CLSIDKey.DeleteSubKeyTree (ourGUID);
}
catch (Exception e)
{
Console.WriteLine ("Can't delete CLSID " + ourGUID + "
from registry. Details:" + e);
}
CLSIDKey.Close ();
.....

The output is:

Can't delete CLSID from registry.
Details:System.UnauthorizedAccessException: Cannot write
to the registry key.
at Microsoft.Win32.RegistryKey.ValidateState(Boolean
needWrite)
at Microsoft.Win32.RegistryKey.DeleteSubKeyTree(String
subkey)
at Registrar.Main(String[] args)

Does anybody know what's the problem? How does the
correct code look like?

Thanks in advance.

Archived from group: microsoft>public>dotnet>security
Back to top
View user's profile Send private message
Dmitry Shaporenkov



Joined: 08 Aug 2007
Posts: 3

PostPosted: Mon Sep 15, 2003 5:09 am    Post subject: RegistryKey.DeleteSubKeyTree throws an UnathorizedAccessExce Reply with quote

>-----Original Message-----
>Hi all,
>
>I know this topis was already discussed in the
newsgroup,
>but I can't find any conclusions. The problem is that
>when I try to use RegistryKey.DeleteSubKeyTree, it
throws
>an UnauthorizedAccessException. I'am a local
>administrator on my machine, and the .NET framework
>configuration has not been changed since install time.
>The code snippet is as follows:
>.....
>RegistryKey CLSIDKey = Registry.ClassesRoot.OpenSubKey
>("CLSID");
>try
>{
> RegistryPermission regPerm = new RegistryPermission
>(RegistryPermissionAccess.Write, CLSIDKey.Name + "\\" +
>ourGUID);
> CLSIDKey.DeleteSubKeyTree (ourGUID);
>}
>catch (Exception e)
>{
> Console.WriteLine ("Can't delete CLSID " + ourGUID + "
>from registry. Details:" + e);
>}
>CLSIDKey.Close ();
>.....
>
>The output is:
>
>Can't delete CLSID from registry.
>Details:System.UnauthorizedAccessException: Cannot write
>to the registry key.
> at Microsoft.Win32.RegistryKey.ValidateState(Boolean
>needWrite)
> at Microsoft.Win32.RegistryKey.DeleteSubKeyTree
(String
>subkey)
> at Registrar.Main(String[] args)
>
>Does anybody know what's the problem? How does the
>correct code look like?
>
The problem was that I was opening the parent key
without write permissions. The correct code is:
....
>RegistryKey CLSIDKey = Registry.ClassesRoot.OpenSubKey
>("CLSID", true);
....

Ugh...

Back to top
View user's profile Send private message
Display posts from previous:   
Related Topics:
MD5CryptoServiceProvider.ComputeHash throws CryptographicExc I have a web service that authenticates users. Passwords are On one machine, after about 8 hours and about 25K I begin to get the following every time: The parameter i

COM + Remoting throws InvalidCastException I am cross-posting to two newsgroups since it is apparently related to both. I have a .NET Windows Service which marshals a .NET objects through a TCP Channel to clients. This object has several methods that return other objects of classes from its assemb

OleDbDataAdapter throws DBConcurrencyException on update Hello, I am writing a C# application that manipulates data in an Access database. I have am using the to fill a DataSet with the records from the database, whenever I attempt to update the same record during a session a

Creating a TcpChannel throws exception Creating a TcpChannel throws the following error: for threw an exception." Code snippet: // Exception occurs at this line channel = new This exception occurs only

DirectoryEntry.Exists() throws COMException Hi; On Windows 2003 when I call: and the SMTP server is not installed, it thrown a COMException with "Unknown error (0x80005000) Shouldn't this always return true or false and never throw an exception? T
Post new topic   Reply to topic    MSDOTnet.org Forum Index -> Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group