function ServiceStart(sMachine, sService : string ) : boolean;
var
schm, schs : SC_Handle;
ss : TServiceStatus;
psTemp : PChar;
dwChkP : DWord;
begin
//서비스 시작하기
ss.dwCurrentState := DWORD(-1);
schm := OpenSCManager(PChar(sMachine), Nil, SC_MANAGER_CONNECT);
if(schm > 0)then
begin
schs := OpenService(schm, PChar(sService), SERVICE_START or SERVICE_QUERY_STATUS);
if(schs > 0)then
begin
psTemp := Nil;
if(StartService(schs, 0, psTemp))then
begin
if(QueryServiceStatus(schs, ss))then
begin
while(SERVICE_RUNNING <> ss.dwCurrentState)do
begin
dwChkP := ss.dwCheckPoint;
Sleep(ss.dwWaitHint);
if(not QueryServiceStatus(schs, ss))then
begin
break;
end;
if(ss.dwCheckPoint < dwChkP)then
begin
break;
end;
end;
end;
end;
CloseServiceHandle(schs);
end;
CloseServiceHandle(schm);
end;
Result := SERVICE_RUNNING = ss.dwCurrentState;
end;
function ServiceStop(sMachine, sService : string ) : boolean;
var
schm, schs : SC_Handle;
ss : TServiceStatus;
dwChkP : DWord;
begin
//서비스 종료하기
schm := OpenSCManager(PChar(sMachine), Nil, SC_MANAGER_CONNECT);
if(schm > 0)then
begin
schs := OpenService(schm, PChar(sService), SERVICE_STOP or SERVICE_QUERY_STATUS);
if(schs > 0)then
begin
if(ControlService(schs, SERVICE_CONTROL_STOP, ss))then
begin
if(QueryServiceStatus(schs, ss))then
begin
while(SERVICE_STOPPED <> ss.dwCurrentState)do
begin
dwChkP := ss.dwCheckPoint;
Sleep(ss.dwWaitHint);
if(not QueryServiceStatus(schs, ss))then
begin
break;
end;
if(ss.dwCheckPoint < dwChkP)then
begin
break;
end;
end;
end;
end;
CloseServiceHandle(schs);
end;
CloseServiceHandle(schm);
end;
Result := SERVICE_STOPPED = ss.dwCurrentState;
end;
ex) ServiceStop('', 'servicename');
ServiceStart('', 'servicename');
'델파이' 카테고리의 다른 글
폼 처럼 <-> 표시가 나오며 크기가 변하는 코딩법 (0) | 2008.12.29 |
---|---|
Delphi 2007에서 DSPack 설치하기 (0) | 2008.12.29 |
델파이로 DirectShow 프로그래밍하기(5) - 어플(1) (0) | 2008.12.29 |
델파이로 DirectShow 프로그래밍하기(4) - GraphEdit_2 (0) | 2008.12.29 |
델파이로 DirectShow 프로그래밍하기(3) - GraphEdit_1 (0) | 2008.12.29 |