Click here to Skip to main content
15,917,329 members
Home / Discussions / C#
   

C#

 
GeneralRe: C#.NET run exe one time at one machine Pin
sindhutiwari1-Feb-08 18:16
sindhutiwari1-Feb-08 18:16 
GeneralRe: C#.NET run exe one time at one machine Pin
E_Gold1-Feb-08 21:15
E_Gold1-Feb-08 21:15 
GeneralRe: C#.NET run exe one time at one machine Pin
Giorgi Dalakishvili1-Feb-08 23:37
mentorGiorgi Dalakishvili1-Feb-08 23:37 
GeneralRe: C#.NET run exe one time at one machine Pin
#realJSOP2-Feb-08 0:49
professional#realJSOP2-Feb-08 0:49 
GeneralRe: C#.NET run exe one time at one machine Pin
Giorgi Dalakishvili2-Feb-08 1:14
mentorGiorgi Dalakishvili2-Feb-08 1:14 
GeneralRe: C#.NET run exe one time at one machine Pin
Paul Conrad2-Feb-08 12:11
professionalPaul Conrad2-Feb-08 12:11 
QuestionDatabase validation Pin
Smithakrishnan1-Feb-08 17:15
Smithakrishnan1-Feb-08 17:15 
GeneralRe: Database validation Pin
DaveyM692-Feb-08 0:30
professionalDaveyM692-Feb-08 0:30 
Do you want to detect if MySQL Server is installed?

The code below is straight from Microsoft[^] - I've just altered the name of the service! Adapt it to suit your needs. (You need to add a reference in your project to System.ServiceProcess)

using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceProcess;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main()
        {

            string myServiceName = "MySQL"; //service name of MySQL Server
            string status; //service status (For example, Running or Stopped)

            Console.WriteLine("Service: " + myServiceName);

            //display service status: For example, Running, Stopped, or Paused
            ServiceController mySC = new ServiceController(myServiceName);

            try
            {
                status = mySC.Status.ToString();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Service not found. It is probably not installed. [exception=" + ex.Message + "]");
                Console.ReadLine();

                return;

            }

            //display service status: For example, Running, Stopped, or Paused
            Console.WriteLine("Service status : " + status);

            //if service is Stopped or StopPending, you can run it with the following code.
            if (mySC.Status.Equals(ServiceControllerStatus.Stopped) | mySC.Status.Equals(ServiceControllerStatus.StopPending))
            {
                try
                {
                    Console.WriteLine("Starting the service...");
                    mySC.Start();
                    mySC.WaitForStatus(ServiceControllerStatus.Running);
                    Console.WriteLine("The service is now " + mySC.Status.ToString());
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error in starting the service: " + ex.Message);

                }

            }

            Console.WriteLine("Press a key to end the application...");
            Console.ReadLine();

            return;

        }

    }
}

GeneralRe: Database validation Pin
DaveyM693-Feb-08 0:05
professionalDaveyM693-Feb-08 0:05 
GeneralOK that's a new one (strange use of colon operator) Pin
Jasmine25011-Feb-08 11:14
Jasmine25011-Feb-08 11:14 
GeneralRe: OK that's a new one (strange use of colon operator) Pin
Guffa1-Feb-08 11:22
Guffa1-Feb-08 11:22 
GeneralRe: OK that's a new one (strange use of colon operator) Pin
led mike1-Feb-08 11:27
led mike1-Feb-08 11:27 
GeneralRe: OK that's a new one (strange use of colon operator) Pin
Pete O'Hanlon1-Feb-08 11:37
mvePete O'Hanlon1-Feb-08 11:37 
GeneralRe: OK that's a new one (strange use of colon operator) Pin
Colin Angus Mackay1-Feb-08 14:42
Colin Angus Mackay1-Feb-08 14:42 
GeneralRe: OK that's a new one (strange use of colon operator) Pin
Jasmine25012-Feb-08 14:09
Jasmine25012-Feb-08 14:09 
GeneralRe: OK that's a new one (strange use of colon operator) Pin
peterchen2-Feb-08 14:42
peterchen2-Feb-08 14:42 
GeneralRe: OK that's a new one (strange use of colon operator) Pin
Jasmine25012-Feb-08 20:16
Jasmine25012-Feb-08 20:16 
QuestionA More Generic Way? Pin
#realJSOP1-Feb-08 10:46
professional#realJSOP1-Feb-08 10:46 
AnswerRe: A More Generic Way? Pin
leppie1-Feb-08 10:57
leppie1-Feb-08 10:57 
GeneralRe: A More Generic Way? Pin
#realJSOP1-Feb-08 11:04
professional#realJSOP1-Feb-08 11:04 
GeneralRe: A More Generic Way? [modified] Pin
Pete O'Hanlon1-Feb-08 11:30
mvePete O'Hanlon1-Feb-08 11:30 
GeneralRe: A More Generic Way? Pin
leppie1-Feb-08 11:31
leppie1-Feb-08 11:31 
GeneralRe: A More Generic Way? Pin
Pete O'Hanlon1-Feb-08 11:33
mvePete O'Hanlon1-Feb-08 11:33 
GeneralRe: A More Generic Way? Pin
leppie1-Feb-08 11:39
leppie1-Feb-08 11:39 
GeneralRe: A More Generic Way? Pin
leppie1-Feb-08 11:40
leppie1-Feb-08 11:40 

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.