C
catbrother
Unregistered / Unconfirmed
GUEST, unregistred user!
在一台XP系统的计算机上执行一下代码<br>function TForm_Main.ReStartServer(HostName , ServiceName : string) : Boolean;<br>var<br> SCM, SCH: SC_Handle;<br> spTemp : PChar;<br> ServiceStatus: TServiceStatus;<br>begin<br> Result := False;<br> SCM := OpenSCManager(PChar(HostName), nil, SC_MANAGER_ALL_ACCESS);<br> if SCM <> 0 then<br> begin<br> SCH := OpenService(SCM, PChar(ServiceName), SC_MANAGER_ALL_ACCESS);<br> if SCH <> 0 then<br> begin<br> QueryServiceStatus(SCH, ServiceStatus);<br> if Not (ServiceStatus.dwCurrentState = SERVICE_STOPPED ) then<br> Result := ControlService(SCH, SERVICE_CONTROL_STOP, ServiceStatus);<br><br> if Result then<br> begin<br> repeat<br> QueryServiceStatus(SCH, ServiceStatus);<br> Sleep(1000);<br> until (ServiceStatus.dwCurrentState = SERVICE_STOPPED);<br> spTemp := nil;<br> Result := StartService(SCH, 0, spTemp );<br> end;<br> CloseServiceHandle(SCH);<br> end;<br> CloseServiceHandle(SCM);<br> end;<br>end;<br><br>可以控制本地服务重新启动,但是无法控制其他计算机后台服务重启。<br>曾经有一段时间可以控制一台Win2000的服务器,奇怪的就是现在又不行了!<br><br>哪位老大能帮着看看,还要做什么工作啊?