I want to control a MySQL service from a .NETCore project. I was able to do this in a .NETFramework 4.7 project with a reference to System.ServiceProcess.dll. .NETCore projects seem to use a different System.ServiceProcess.dll which has less functionality.
Is there a different way to control a MySQL service using .NETCore? Can I just reference the .NETFramework dll from a .NETCore project?
I make it work. It's as follows:
Check whether the Alerter service is started.
ServiceController sc = new ServiceController();
sc.ServiceName = "Alerter";
Console.WriteLine("The Alerter service status is currently set to {0}", sc.Status.ToString());
if (sc.Status == ServiceControllerStatus.Stopped)
{
// Start the service if the current status is stopped.
Console.WriteLine("Starting the Alerter service...");
try
{
// Start the service, and wait until its status is "Running".
sc.Start();
sc.WaitForStatus(ServiceControllerStatus.Running);
// Display the current service status.
Console.WriteLine("The Alerter service status is now set to {0}.", sc.Status.ToString());
}
catch (InvalidOperationException)
{
Console.WriteLine("Could not start the Alerter service.");
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With