自己搞掂。。<br>function StartService(AServName: string): Boolean; //use WinSvc<br>var<br> SCManager, hService: SC_HANDLE;<br> lpServiceArgVectors: PChar;<br>begin<br> SCManager := OpenSCManager(nil, nil, SC_MANAGER_ALL_ACCESS);<br> Result := SCManager <> 0;<br> if Result then<br> try<br> hService := OpenService(SCManager, PChar(AServName), SERVICE_ALL_ACCESS);<br> Result := hService <> 0;<br> if (hService = 0) and (GetLastError = ERROR_SERVICE_DOES_NOT_EXIST) then<br> Exception.Create('The specified service does not exist');<br> if hService <> 0 then<br> try<br> lpServiceArgVectors := nil;<br> Result := WinSvc.StartService(hService, 0, PChar(lpServiceArgVectors));<br> if not Result and (GetLastError = ERROR_SERVICE_ALREADY_RUNNING) then<br> Result := True;<br> finally<br> CloseServiceHandle(hService);<br> end;<br> finally<br> CloseServiceHandle(SCManager);<br> end;<br>end;<br><br><br>function StopService(AServName: string): Boolean;<br>var<br> SCManager, hService: SC_HANDLE;<br> SvcStatus: TServiceStatus;<br>begin<br> SCManager := OpenSCManager(nil, nil, SC_MANAGER_ALL_ACCESS);<br> Result := SCManager <> 0;<br> if Result then<br> try<br> hService := OpenService(SCManager, PChar(AServName), SERVICE_ALL_ACCESS);<br> Result := hService <> 0;<br> if Result then<br> try //停止并卸载服务;<br> Result := ControlService(hService, SERVICE_CONTROL_STOP, SvcStatus);<br> //删除服务,这一句可以不要;<br>// DeleteService(hService);<br> finally<br> CloseServiceHandle(hService);<br> end;<br> finally<br> CloseServiceHandle(SCManager);<br> end;<br>end;