When calling the following code, .NET issues Access is denied. I would like to use the System.Diagnostics library to obtain information about a process.
Process[] processes = Process.GetProcessesByName("MyProcess");
if (processes.Any())
{
var process = processes[0];
// Access is denied
var startTime = process.StartTime;
}
The above code is part of an HttpGet method of an ASP.NET MVC Core 2.2 service running on IIS 10 (so far all locally). I am using System.Diagnostic.Process 4.3.0.
Adding the IIS Apppool to the local administrators group did not help. And that makes some sense given the documentation for this property which states that the Process class contains a link demand, and that "A SecurityException is thrown when either the immediate caller or the derived class does not have full-trust permission." The problem is that i do not understand how to provide full-trust in .net core web applications, and i haven't found any good examples on link demands. Is it in web.config - which part i thought went away with .net core if not earlier?
The process in which i am interested is a window console application in the same solution, but launched by a windows scheduler.
I would expect to get the Process.StartTime, but instead get Access is denied. However, I am missing something in my security configuration.
So, assuming that IIS AppPool is the executor of the HttpGet, and the other process - a windows console application - is running independently, how do i configure the security to enable a successful call of Process.StartTime?
PS - I have tried the [SecurityCritical] annotation on the method - no success.