Re: DeleteSubKeyTree fails with UnauthorizedAccessException
From: Stephen McCloskey [MSFT] (stemccl_at_online.microsoft.com)
Date: 06/18/03
- Next message: Stephen McCloskey [MSFT]: "Re: Reflection permission denied"
- Previous message: Norbert Ruessmann: "Re: Reflection permission denied"
- In reply to: Mark Lythgoe: "DeleteSubKeyTree fails with UnauthorizedAccessException"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Tue, 17 Jun 2003 15:21:21 -0700
Are you running the app from a local drive? Perhaps the application is
running in partial trust.
> RegistryPermission p = new RegistryPermission
> (RegistryPermissionAccess.AllAccess, "HKEY_CLASSES_ROOT\\CL
> SID\\");
> p.Assert();
> p.Demand();
Note that an assembly can't programmatically entice the CLR to grant it more
permission that it would otherwise receive. (It can refuse permissions,
however.) The administrator of the machine always has final control over
which permissions get granted. The programmer really doesn't (and
shouldn't) have too much control over what gets granted. So, this code
won't help things if this turns out to be a permission problem and won't
really allow you to troubleshoot.
The Demand and Assert operations are usually placed in libraries (that are
highly trusted) and are used to protect themselves from other libraries and
exes (that are not trusted.) You can't, for example, use a Demand or an
Assert within an exe to influence the permissions it will receive.
Use Demand in a library that has Permission X to require that all callers
(in different assemblies) also have permission X.
Use Assert in a Library, Foo, that has Permission X (Foo is required to have
Permission X because it calls another library, Bar ) when you do not want to
require that callers of Foo have permission X.
Stephen
"Mark Lythgoe" <regspam.10.beachvbbum@spamgourmet.com> wrote in message
news:043e01c3343d$36259d30$a101280a@phx.gbl...
> I have tried just about every combination of assembly and
> method-level RegistryPermission attributes to no avail. I
> have checked the code access level and it is
> unrestricted. My account is the local administrator on my
> machine and I can delete the registry keys manually
> without problem. The code is;
> RegistryKey CLSID = Registry.ClassesRoot.OpenSubKey
> ("CLSID");
> init();//UI stuff
> ctlStatusBar.Text = "Removing
> registry keys";//UI stuff
> this.Refresh(); //UI stuff
> foreach (int index in
> ctlItemsToDelete.CheckedIndices){
> ctlStatusBar.Text
> = "Removing " + (string)CLSID.OpenSubKey(_aItems
> [index]).GetValue("");//UI stuff
> this.Refresh();
> CLSID.DeleteSubKeyTree
> (_aItems[index]);//fails
> }
> basically it is just presenting the user with a list of
> registered COM classes to delete and then trying to delete
> them from HKEY_CLASSES_ROOT\CLSID.
>
> Anyone got any ideas?
>
> Mark
>
> PS: When I add the following above my code;
> RegistryPermission p = new RegistryPermission
> (RegistryPermissionAccess.AllAccess, "HKEY_CLASSES_ROOT\\CL
> SID\\");
> p.Assert();
> p.Demand();
> I get no errors or assertions, I have also tried
> RegistryPermission p = new RegistryPermission
> (PermissionState.Unrestricted);
- Next message: Stephen McCloskey [MSFT]: "Re: Reflection permission denied"
- Previous message: Norbert Ruessmann: "Re: Reflection permission denied"
- In reply to: Mark Lythgoe: "DeleteSubKeyTree fails with UnauthorizedAccessException"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|