0

To start Wamp Server i am using following code.

Process[] pname = Process.GetProcessesByName("wampmanager");
if (pname.Length == 0)
{
    Process.Start(@"C:\wamp\wampmanager");
    Thread.Sleep(700);
}

Now , actually i want to Check MySql Service. If already it is not running, start it.

I found answer nearest to my question how do start/stop services using net stop command in c# But in my case, I found message MySql service is not found on machine.

Allah Rakha
  • 65
  • 2
  • 11
  • What is your core question? How to detect if a service is avaiable? How to start it? Why you can't start MySQL on your machine? – Link Oct 27 '17 at 19:43
  • @Link , I have updated my question . Hope so , it will help you to find solution regarding to my problem. – Allah Rakha Oct 27 '17 at 19:52
  • I don't know how wamp works. Can you check if the MySQL-Service is listed in your service snap-in? – Link Oct 27 '17 at 19:56
  • I'm not really sure what other answer you expect form us, than what is written in the linked question. You must confirm the name of your mysql service and make sure that your code uses that name. – Shadow Oct 27 '17 at 19:56

1 Answers1

0

Start MYQSL

using System.ServiceProcess;
ServiceController controller  = new ServiceController();

controller.MachineName = ".";
controller.ServiceName = "mysql";

// Start the service
controller.Start();

// Stop the service
controller.Stop();
Waruna Manjula
  • 3,067
  • 1
  • 34
  • 33