Форум: "Начинающим";
Текущий архив: 2008.05.11;
Скачать: [xml.tar.bz2];
ВнизУправление службами в Windows XP Найти похожие ветки
← →
dmdel (2008-04-10 16:01) [0]Здраствуйте.
Как можно с помощью Дельфи 6 отключить какую либо службу, а потом ее включить?
← →
Palladin © (2008-04-10 16:15) [1]
Uses
WinSvc;
Function vtServiceStart(Const p_strComp,p_strServiceName:String):Boolean;
Var
hManager,hSvc:SC_Handle;
nSvcStatus:TServiceStatus;
Temp:PChar;
dwCheckPoint:DWord;
Begin
ZeroMemory(@nSvcStatus,SizeOf(nSvcStatus));
nSvcStatus.dwCurrentState:=1;
hManager:=OpenSCManager(PChar(p_strComp),Nil,SC_MANAGER_CONNECT);
If hManager>0 Then
Begin
hSvc:=OpenService(hManager,PChar(p_strServiceName),SERVICE_START or SERVICE_QUERY_STATUS);
If hSvc>0 Then
Begin
Temp:=nil;
If StartService(hSvc,0,temp) Then
If QueryServiceStatus(hSvc,nSvcStatus) Then
While SERVICE_RUNNING<>nSvcStatus.dwCurrentState Do
Begin
dwCheckPoint:=nSvcStatus.dwCheckPoint;
Sleep(nSvcStatus.dwWaitHint);
If Not QueryServiceStatus(hSvc,nSvcStatus) Then Break;
If (nSvcStatus.dwCheckPoint<dwCheckPoint) then Break;
End;
CloseServiceHandle(hSvc);
End;
CloseServiceHandle(hManager);
End;
Result:=SERVICE_RUNNING=nSvcStatus.dwCurrentState;
End;
Function vtServiceStop(Const p_strMachine,p_strServiceName:String):Boolean;
Var
hManager,hSvc:SC_Handle;
nSvcStatus:TServiceStatus;
dwCheckPoint:DWord;
Begin
hManager:=OpenSCManager(PChar(p_strMachine),Nil,SC_MANAGER_CONNECT);
If hManager>0 Then
Begin
hSvc:=OpenService(hManager,PChar(p_strServiceName),SERVICE_STOP or SERVICE_QUERY_STATUS);
If hSvc>0 Then
Begin
If ControlService(hSvc,SERVICE_CONTROL_STOP,nSvcStatus) Then
If QueryServiceStatus(hSvc,nSvcStatus) Then
While SERVICE_STOPPED<>nSvcStatus.dwCurrentState Do
Begin
dwCheckPoint:=nSvcStatus.dwCheckPoint;
Sleep(nSvcStatus.dwWaitHint);
If Not QueryServiceStatus(hSvc,nSvcStatus) Then Break;
If nSvcStatus.dwCheckPoint<dwCheckPoint Then Break;
End;
CloseServiceHandle(hSvc);
End;
CloseServiceHandle(hManager);
End;
Result:=SERVICE_STOPPED=nSvcStatus.dwCurrentState;
End;
Function vtServiceGetStatus(Const p_strMachine,p_strService:String):DWord;
Var
hManager,hSvc:SC_Handle;
nSvcStatus:TServiceStatus;
hStat:DWord;
Begin
hStat:=1;
hManager:=OpenSCManager(PChar(p_strMachine),Nil,SC_MANAGER_CONNECT);
If hManager>0 Then
Begin
hSvc:=OpenService(hManager,PChar(p_strService),SERVICE_QUERY_STATUS);
If hSvc>0 Then
Begin
If QueryServiceStatus(hSvc,nSvcStatus) Then hStat:=nSvcStatus.dwCurrentState;
CloseServiceHandle(hSvc);
End;
CloseServiceHandle(hManager);
End;
Result:=hStat;
End;
← →
dmdel (2008-04-10 16:23) [2]Спаисбо
← →
Palladin © (2008-04-10 16:28) [3]Пожаулста
Страницы: 1 вся ветка
Форум: "Начинающим";
Текущий архив: 2008.05.11;
Скачать: [xml.tar.bz2];
Память: 0.45 MB
Время: 0.007 c