C# 如何在c语言中以编程方式启动apache和mysql服务#

C# 如何在c语言中以编程方式启动apache和mysql服务#,c#,mysql,apache,C#,Mysql,Apache,我开发了一个程序,它有一个数据库并使用MySql 但我希望它是一个用户友好的,因为每次你启动程序。 您需要启动xampp控制面板并启动这些服务 我不喜欢它,因为如果有人不能启动它,程序就不能正常工作。这不是用户友好的 因此,我想让它用户友好,当启动屏幕启动时,它将自动从后台启动这些服务 我在网上搜索过,但找不到合适的 虽然我尝试了这个,它启动了apache,但它在命令行上像打印“apachestarting”一样出现问题,并卡在上面。尽管apache启动了 这是我测试过的代码: ProcessS

我开发了一个程序,它有一个数据库并使用MySql 但我希望它是一个用户友好的,因为每次你启动程序。 您需要启动xampp控制面板并启动这些服务

我不喜欢它,因为如果有人不能启动它,程序就不能正常工作。这不是用户友好的

因此,我想让它用户友好,当启动屏幕启动时,它将自动从后台启动这些服务

我在网上搜索过,但找不到合适的 虽然我尝试了这个,它启动了apache,但它在命令行上像打印“apachestarting”一样出现问题,并卡在上面。尽管apache启动了

这是我测试过的代码:

ProcessStartInfo apa = new ProcessStartInfo();
apa.Verb = "runas";
apa.CreateNoWindow = false;
apa.UseShellExecute = false;
apa.FileName = "c:\\xampp\\apache_start.bat";
apa.WindowStyle = ProcessWindowStyle.Hidden;
using (Process exeProcess = Process.Start(apa))
{
    exeProcess.WaitForExit();
}

Thanks pal. All I need is to help me to start that APACHE and MYSQL services without using xampp  .

您可以使用
ServiceController

ServiceController apache = new ServiceController("<your service name here>");
    if (apache.Status == ServiceControllerStatus.Stopped){
       apache.Start();
    }

thx用于重复呼叫。这应该是一个注释,而不仅仅是他们代码的副本。干杯
using System.ServiceProcess;
ServiceController controller  = new ServiceController();

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

// Start the service
controller.Start();

// Stop the service
controller.Stop();