Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

Process.MainModule Access Is Denied

$
0
0

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();

        }
    }


Viewing all articles
Browse latest Browse all 8156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>