简单的
WinExec('net stop 服务名',SW_HIDE);
WinExec('net start 服务名',SW_HIDE);
正规的:
SC_HANDLE svcmgr=OpenSCManager(机器名或者用空字符串表示本机,NULL,STANDARD_RIGHTS_REQUIRED);
if(!svcmgr)
RaiseLastWin32Error();
SC_HANDLE svc=OpenService(svcmgr,"schedule",SERVICE_ALL_ACCESS);
if(!svc)
{
CloseServiceHandle(svcmgr);
RaiseLastWin32Error();
}
StartService(svc,0,0); //关闭的话,用ControlService
CloseServiceHandle(svcmgr);
CloseServiceHandle(svc);