giasone 0 Newbie Poster

I am trying to test for a serice down situation if the first condition in the if statements is true, that is, the first service is down, then the program sends out the email notification and it works as it should. But if it isn't the only the that happens is that the form pops up and it does not test for any of the other conditions.

Can anyone help with this please.

Thank-you.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.ServiceProcess;
using System.Net.Mail;
using System.Net;



namespace ServiceTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string computer_name = System.Environment.GetEnvironmentVariable("COMPUTERNAME");
        //    string mailbody = "This is to let you know that the " + computer_name + " Netlogon service is down!!";
            MailMessage mail = new MailMessage();
            SmtpClient client = new SmtpClient();
            mail.Subject = (computer_name + " is down - This is a test email only - no server services are down" );
            mail.From = new MailAddress("servicedown@test.com");




            client.Host = "192.168.125.12";
            client.Port = 25;
           mail.To.Add(new MailAddress("jon@test.com"));
             mail.To.Add(new MailAddress("jason@test.com"));
             mail.To.Add(new MailAddress("mike@test.com"));





             ServiceController net = new ServiceController("Netlogon");
            ServiceController unirs = new ServiceController("Universe Resource Service");
            ServiceController unirpc = new ServiceController("Uni RPC Service");
            ServiceController unitelnet = new ServiceController("Universe Telnet Service");

            // This will test the Universe Resource Service
            if ((unirs.Status.Equals(ServiceControllerStatus.Stopped)) ||
                 (unirs.Status.Equals(ServiceControllerStatus.StopPending)))
            {


                mail.Body = "This is to let you know that the " + computer_name + " Universe Resource Service service is down!!";

                client.Send(mail);

            }


            // This will test the Netlogon Service
            if ((net.Status.Equals(ServiceControllerStatus.Stopped)) ||
               (net.Status.Equals(ServiceControllerStatus.StopPending)))
            {


                mail.Body = "This is to let you know that the computer " + computer_name + " Netlogon service is down!!";

                client.Send(mail);

            }


            // This will test the Universe Telnet service
            if ((unitelnet.Status.Equals(ServiceControllerStatus.Stopped)) ||
            (unitelnet.Status.Equals(ServiceControllerStatus.StopPending)))
            {


                mail.Body = "This is to let you know that the computer " + computer_name + " Universe Telnet service is down!!";

                client.Send(mail);

            }


            Environment.Exit(1);
        }
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.