2

is there a way to setup an AppDomain's permissions such that the code running inside cannot kill the process that launched it ?

More precisely suppose I have an AppDomain appDomain, I would like to do something like

try
{
    appDomain.ExecuteAssembly("someAssembly.exe");
}catch(SomeForbiddenActionException e){

    Console.WriteLine("someAssembly tried to perform some forbidden action")
}

Suppose someAssembly.exe executes the following code:

static void Main(){
    Process.GetCurrentProcess().Kill();
}

For the moment, if I run the code above, the whole application exits, which I would like to avoid at all cost, I would like the call to Process.GetCurrentProcess().Kill(); to raise an exception because it is forbidden. I tried to find some way of setting up the Evidence and/or PermissionSet during the setup of the app domain to prevent that but without success:

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

did not give me any clue on how to achieve my goal.

appDomain.ProcessExit is just a chance to call some code when the process is exiting already => not a good option

Any help or clues are very welcome, thanks !

Wasabi
  • 456
  • 1
  • 4
  • 12

1 Answers1

0

You can subscribe to the process being exited, though I'm not sure that this will help you prevent the process from being killed.

MSDN info

var myProcess =  Process.GetCurrentProcess();
myProcess.Exited += new EventHandler(myProcess_Exited);

private void myProcess_Exited(object sender, System.EventArgs e)
{
     //not sure if there is a way to prevent the process from exiting here.
}
DLeh
  • 23,806
  • 16
  • 84
  • 128