我已经开发了一个程序,它有一个数据库,并使用MySql,但我希望它是一个用户友好的,因为每次你启动程序。您需要启动xampp控制面板并启动这些服务。
我不喜欢它,因为如果有人不能启动它,程序就不能正常工作。这对用户不友好
所以我想让它变得用户友好,当闪屏启动时,它将自动从后台启动这些服务。
我已经在互联网上搜索过了,但是我找不到合适的那个,虽然我试过这个,它启动了apache,但是它在命令行上卡住了,就像打印'apache start‘一样。虽然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 .发布于 2016-10-10 12:18:38
您可以使用ServiceController
ServiceController apache = new ServiceController("<your service name here>");
if (apache.Status == ServiceControllerStatus.Stopped){
apache.Start();
}与MySQL类似
using System.ServiceProcess;
ServiceController controller = new ServiceController();
controller.MachineName = ".";
controller.ServiceName = "mysql";
// Start the service
controller.Start();
// Stop the service
controller.Stop();https://stackoverflow.com/questions/39951178
复制相似问题