Небольшой фрагмент кода, который вы должны начать:
/* Open service control manager. */
SC_HANDLE scm_handle = OpenSCManager(0,
0,
SC_MANAGER_ALL_ACCESS);
/* Ensure (0 != scm_handle) */
/* Open service. */
SC_HANDLE service_handle = OpenService(scm_handle,
"mysql-service-name",
SERVICE_ALL_ACCESS);
/* Ensure (0 != service_handle) */
/* Try to stop the service if it is running. */
SERVICE_STATUS status; /* This may need populated differently for mysql. */
status.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
if (ControlService(service_handle, SERVICE_CONTROL_STOP, &status))
{
Sleep(1000);
while (QueryServiceStatus(service_handle, &status))
{
if(status.dwCurrentState == SERVICE_STOP_PENDING)
{
Sleep(1000);
}
else
{
break;
}
}
if (status.dwCurrentState == SERVICE_STOPPED)
{
/* Success: service stopped. */
}
else
{
/* Failure: service not stopped. */
}
}
else
{
/* Failed to issue stop request. */
}
CloseServiceHandle(service_handle);
CloseServiceHandle(scm_handle);