Hi,
I'm using the System.Diagnostics.Process.GetProcessByName() to get access to a wcf service host that runs as a windows service.
The process hosts multiple services and I'm trying to access the WorkingSet64 for one of the services. When i call System.Diagnostics.Process.GetProcessByName() 4 processes are returned for the name provided, when i loop through these processes and access the Process.MainModule.Filename i get an "Access Denied" error.
The process runs as a system process, when i run the code on my dev machine it seems to return the information i am expecting (ACL is turned off) when i run the code on the server (ACL turned on) an access is denied exception is thrown.
I've seen this issue mentioned in a few places but most of the answers suggest to just skip the inaccessible items with a try catch and that isn't what i want, i need to inspect the inaccessible items.
Thanks
Aaron
Code to reproduce
class Program { static void Main(string[] args) { Process[] service; service = Process.GetProcesses(); Console.WriteLine(service.Count()); foreach (var s in service) { Console.WriteLine(s.ProcessName); try { Console.WriteLine(s.WorkingSet64); } catch (Exception ex) { Console.WriteLine("ERROR---" + ex.Message); } Console.WriteLine("-------------------"); } Console.ReadLine(); } }