Click here to Skip to main content
15,891,033 members
Articles / Programming Languages / C#

Monitor System Information

Rate me:
Please Sign up or sign in to vote.
4.69/5 (11 votes)
18 Jul 2009CPOL2 min read 44K   7K   61   5
A program to monitor and collect basic system information from remote machines.

Introduction

Monitor Center is a system designed to help you control and monitor your computers in a local network. The system allows you to see, in real time, useful information about any of your computers using an easy interface that can be suited to your own needs.

This article supplies examples of how to access different information on the Windows Operating System, such as process information, performance counters, and basic system information.

MonitorSystem.gif

Background

The program uses the .NET Framework libraries in order to get the requested information.

Using the code

How can you use the program?

After you unzipp the demo file, copy MonitorCenter1.0.exe from the Server folder to any location on the server machine. This EXE is the central interface of the system from which you can perform all your actions on each one of the clients you wish to monitor (including the machine on which MonitorCenter1.0.exe is located). After this, copy the folder named Client to a location of your choice.

You can read the User Guide document that is included in the demo zip file for further instructions about using the program.

Now, the system is ready for use; just run both the server and client exe files! Here are some examples of collecting the required information.

Reading the processes information:

C#
using System.Diagnostic;

Process[] ProcessList = Process.GetProcesses();

foreach (Process CurrProcess in ProcessList)
{
    Console.WriteLine("Process Name:" + CurrProcess.ProcessName);
    Console.WriteLine("Main Module FileName:" + CurrProcess.MainModule.FileName);
    Console.WriteLine("Start Time:" + CurrProcess.CurrProcess.StartTime);
}

The process owner, for example, is not part of the Process class, so we get this data from WMI:

C#
using System.Management;

public string GetProcessOwner(int processID)
{
    string owner = string.Empty;
    string queryString = "Select * From Win32_Process Where ProcessID = " + processID;
    ManagementObjectSearcher searcher = new ManagementObjectSearcher(queryString);
    ManagementObjectCollection processList = searcher.Get(); 

    foreach (ManagementObject currentProcess in processList)
    {
        string[] argList = { string.Empty };
        int returnValue = Convert.ToInt32(currentProcess.InvokeMethod("GetOwner", argList));
        if (returnValue == 0)
            owner = argList[0];
    }

    return owner;
}

In order to get information of the Operating System performance counters, such as CPU usage, use the following code:

C#
using System.Diagnostic;

PerformanceCounter CurrCounter = new PerformanceCounter("Processor%", 
                                 "ProcessorTime", "_Total");
int CPUTimeValue = CurrCounter.NextValue(); 

The information we collected was presented in line graphs which we built using ZedGraph. ZedGraph is an open source which you can download for free and use it to build any kind of graph you like.

All the above code examples are parts of the project source file.

Points of interest

Not all users have permissions to access system information. Moreover, sometimes, even the system administrator cannot access certain data. Use try and catch blocks when accessing information of the Operating System.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Questioncan it work internet??? Pin
jfan20919-Jul-09 2:59
jfan20919-Jul-09 2:59 
Generalmy vote of 1 Pin
mbyamukama16-Jul-09 1:02
mbyamukama16-Jul-09 1:02 
GeneralRe: my vote of 1 Pin
adambl17-Jul-09 2:05
professionaladambl17-Jul-09 2:05 
GeneralAwesome! [modified] Pin
Bit-Smacker14-Jul-09 8:27
Bit-Smacker14-Jul-09 8:27 
Thank you! Thumbs Up | :thumbsup:

I've been wasting time trying to create all of my own system monitors from scratch, and this gave me a huge jump-start. As a bonus, I've been meaning to test-drive the ZedGraph library and you included that functionality as well!

It's a very nice monitoring tool as-is, but I'm planning to use it at a more basic level to only report exceeded threshold triggers for LAN monitoring. It would be nice to come in each morning and have a heads-up on what will be eating up my time.

Thanks for providing such a complete, functional, and useful applcation!

modified on Tuesday, July 14, 2009 2:33 PM

GeneralMore clarification Pin
Md. Marufuzzaman7-Jul-09 22:19
professionalMd. Marufuzzaman7-Jul-09 22:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.