Search code examples
.netelevated-privileges

How do I temporarily lower elevation


The scenario is that I am running a service as admin.

We have a callout that runs custom code ( think scripting ). It uses codedom compiling to create an assembly and create a type and invoke a method (based on code).

I want to temporarily drop admin privileges for the duration of the callout and then restore them afterwards.


Solution

  • I ended up running the code in a sandboxed application domain as described in the link:

    How to: Run Partially Trusted Code in a Sandbox

    http://msdn.microsoft.com/en-us/library/bb763046%28v=vs.100%29.aspx