0

i'm trying to get the actual free memory. It seems to be the easiest solution to use Performance Counters. It works totally fine on my Coding Machine, unfortunately I get an Exception on the target Computer. I use Windows XP an .NET 3.5 Can you please help me?

Code:

namespace TestConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            PerformanceCounter ramCounter = new PerformanceCounter("Memory", "Available Bytes");
        }
    }
}

Exception:

Unhandled Exception: System.InvalidOperationException: Category does not exist.
   at System.Diagnostics.PerformanceCounterLib.CounterExists(String machine, String category, String counter)
   at System.Diagnostics.PerformanceCounter.Initialize()
   at System.Diagnostics.PerformanceCounter..ctor(String categoryName, String counterName, String instanceName, Boolean
readOnly)
   at System.Diagnostics.PerformanceCounter..ctor(String categoryName, String counterName)
   at TestConsole.Program.Main(String[] args) in D:\Projektarbeit\Bachelorarbeit\VS2010\Projekte\DiagStationControllerTe
stConsoleV1\TestConsole\Program.cs:line 15
sloth
  • 99,095
  • 21
  • 171
  • 219
Christian Elsner
  • 113
  • 1
  • 4
  • 15
  • this seems to provide a solution: http://support.microsoft.com/kb/300956/en-us unfortuanly im not allowed to alter the registry on my target – Christian Elsner Jun 18 '12 at 13:03

2 Answers2

0

Exception message says everything:

Category does not exist.

Mean category "Memory" does not exist.

abatishchev
  • 98,240
  • 88
  • 296
  • 433
0

I could not resolve the underlying issue, but there is a workaround by not using PerformanceCounter, but API-Calls, see http://www.codeproject.com/Articles/1285/Calling-API-functions-using-C

Christian Elsner
  • 113
  • 1
  • 4
  • 15