How to run apache as a service on windows using c#

Question: How to run apache as a service on windows using c#

Answer:

using following code snippet you can start apache as a service

var APACHE_SERVICENAME = "MyApacheService";
var apachePath = $@"{txtApachePath.Text}\bin\httpd.exe";
var apacheArgs = $@"-k install -n MyApacheService";

Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.FileName = apachePath;
startInfo.Arguments = apacheArgs;

process.StartInfo = startInfo;
try
{
    process.Start();
}
catch (Exception ex)
{
    MessageBox.Show("ex.Message);
}

Leave a Comment

Scroll to Top