Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2003.04.21;
Скачать: CL | DM;

Вниз

service   Найти похожие ветки 

 
_toltec   (2003-02-21 23:05) [0]

КАк запустить и остановить сервис


 
sniknik ©   (2003-02-21 23:44) [1]

легко. в панель управления->администрировании->службы выбираеш понравившийся сервис клацаеш по нему правой клавишей мыши, в открывшемся попап меню есть пункты пуск/стоп.


 
ZZ ©   (2003-02-21 23:52) [2]

OpenSCManager->OpenService->ControlService (SERVICE_CONTROL_STOP)
->StartService


 
Ihor Osov'yak ©   (2003-02-22 01:07) [3]

Если программно:

unit e0_service;

interface

uses windows;

const
{ Service State -- for CurrentState }
SERVICE_ERROR_OPENING = 0;
SERVICE_STOPPED = $00000001;
SERVICE_START_PENDING = $00000002;
SERVICE_STOP_PENDING = $00000003;
SERVICE_RUNNING = $00000004;
SERVICE_CONTINUE_PENDING = $00000005;
SERVICE_PAUSE_PENDING = $00000006;
SERVICE_PAUSED = $00000007;

function ServiceGetStatus(sMachine, sService: PChar): DWORD;
{
Return Values: see, please, SERVICE_ERROR_OPENING..SERVICE_PAUSED
>> Parameters:
sService: specifies the name of the service to open
sMachine: specifies the name of the target computer
}

function IsServiceRunning(sMachine, sService: PChar): Boolean;

type
dfDoerIdle = procedure (aCurentMs,amaxMS:DWORD) of object;

function ServiceStart(sMachine, sService: PChar; Params: array of string;
aIdleProc:dfDoerIdle): boolean;

function ServiceStop(sMachine, sService: PChar; aIdleProc:dfDoerIdle): boolean;

implementation

uses
WinSvc,
sysutils;


function ServiceGetStatus(sMachine, sService: PChar): DWORD;
{
Return Values: see, please, SERVICE_ERROR_OPENING..SERVICE_PAUSED
>> Parameters:
sService: specifies the name of the service to open
sMachine: specifies the name of the target computer
}
var
SCManHandle, SvcHandle: SC_Handle;
SS: TServiceStatus;
begin
result := 0;
// Open service manager handle.
SCManHandle := OpenSCManager(sMachine, nil, SC_MANAGER_CONNECT);
if (SCManHandle > 0) then begin
SvcHandle := OpenService(SCManHandle, sService, SERVICE_QUERY_STATUS);
// if Service installed
if (SvcHandle > 0) then begin
// SS structure holds the service status (TServiceStatus);
if (QueryServiceStatus(SvcHandle, SS))
then result := ss.dwCurrentState;
CloseServiceHandle(SvcHandle);
end;
CloseServiceHandle(SCManHandle);
end;
end;

function IsServiceRunning(sMachine, sService: PChar): Boolean;
begin
Result := SERVICE_RUNNING = ServiceGetStatus(sMachine, sService);
end;


{
Windows 2000 and earlier: All processes are granted the SC_MANAGER_CONNECT,
SC_MANAGER_ENUMERATE_SERVICE, and SC_MANAGER_QUERY_LOCK_STATUS access rights.

Windows XP: Only authenticated users are granted the SC_MANAGER_CONNECT,
SC_MANAGER_ENUMERATE_SERVICE,
and SC_MANAGER_QUERY_LOCK_STATUS access rights.
}

{
Do not use the service display name (as displayed in the services
control panel applet.) You must use the real service name, as
referenced in the registry under
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services
}


function StrToMultiStr(var pA: PChar; A: array of string): integer;
var
iCount : integer;
i : integer;
P : PChar;
begin
Result := 0;
pA := nil;
iCount := Length(A);
if iCount = 0 then Exit;

for i := 0 to iCount - 1 do Inc(Result, Length(A[i]) + 1);

Inc(Result); { the final null terminator }

pA := AllocMem(Result);
P := pA;

for i := 0 to iCount -1 do begin
P := StrECopy(P, PChar(A[i]));
Inc(P);
end;

P^ := #0;

end;


procedure Wait(aWaitTime:DWORD; aIdleProc:dfDoerIdle);
var startTick:DWORD;
currentTick:DWORD;
begin
if not assigned(aIdleProc) then begin
sleep(awaitTime);
exit;
end;
startTick:= GetTickCount;
repeat
aIdleProc(0,aWaitTime);
currentTick := GetTickCount;
if currentTick<startTick then break;
if currentTick>startTick+aWaitTime then break;
aIdleProc(currentTick-startTick,aWaitTime);
if aWaitTime<10 then sleep(1) else sleep(10);
until false;
aIdleProc(aWaitTime,aWaitTime);
end;

procedure SetControlState(hSvc: SC_HANDLE; WantedState: Cardinal; var SS: TServiceStatus;
aIdleProc:dfDoerIdle);
var
OldCheckPoint : DWORD;
WaitTime : DWORD;
StartTickCount : DWORD;
begin
{ from the SDK, topic : Starting a Service }
if QueryServiceStatus(hSvc, SS) then
begin
StartTickCount := GetTickCount();
OldCheckPoint := SS.dwCheckPoint;

while (SS.dwCurrentState <> WantedState) do
begin
WaitTime := DWORD(SS.dwWaitHint div 10);

if ( WaitTime < 1000 ) then WaitTime := 1000
else if ( WaitTime > 10000 ) then WaitTime := 10000;

{if not assigned(aIdleProc)
then Sleep(WaitTime)
else} Wait(WaitTime,aIdleProc);

if not QueryServiceStatus(hSvc, SS) then Break;

if ( SS.dwCheckPoint > OldCheckPoint )
then begin { The service is making progress }
StartTickCount := GetTickCount();
OldCheckPoint := SS.dwCheckPoint;
end
else begin
if (GetTickCount - StartTickCount > SS.dwWaitHint )
then Break;
end;
end;
end;
end;


Продолжение следует


 
Ihor Osov'yak ©   (2003-02-22 01:08) [4]

продолжение



function ServiceStart(sMachine, sService: PChar; Params: array of string;
aIdleProc:dfDoerIdle): boolean;
var
SCManHandle, SvcHandle: SC_Handle;
SS: TServiceStatus;
pParams : PChar;
ParamLen : integer;
begin
result := false;
// Open service manager handle.
SCManHandle := OpenSCManager(sMachine, nil, SC_MANAGER_CONNECT);
if (SCManHandle > 0) then begin
SvcHandle := OpenService(SCManHandle, sService, SERVICE_ALL_ACCESS);
// if Service installed adn we have permissions
if (SvcHandle > 0) then begin

ParamLen := StrToMultiStr(pParams, Params);
try
if StartService(SvcHandle, Length(Params), pParams) then begin
SetControlState(SvcHandle, SERVICE_RUNNING, SS, aIdleProc);
Result := SS.dwCurrentState = SERVICE_RUNNING;
end;
finally
CloseServiceHandle(SvcHandle);
if ParamLen > 0 then FreeMem(pParams, ParamLen);
end;

end;
CloseServiceHandle(SCManHandle);
end;
end;

function ServiceStop(sMachine, sService: PChar; aIdleProc:dfDoerIdle): boolean;
var
SCManHandle, SvcHandle: SC_Handle;
SS: TServiceStatus;
begin
result := false;
// Open service manager handle.
SCManHandle := OpenSCManager(sMachine, nil, SC_MANAGER_CONNECT);
if (SCManHandle > 0) then begin
SvcHandle := OpenService(SCManHandle, sService, SERVICE_ALL_ACCESS);
// if Service installed adn we have permissions
if (SvcHandle > 0) then begin

try
if ControlService(SvcHandle, SERVICE_CONTROL_STOP, SS)
then begin
SetControlState(SvcHandle, SERVICE_STOPPED, SS,aidleProc);
Result := SS.dwCurrentState = SERVICE_STOPPED;
end;
finally
CloseServiceHandle(SvcHandle);
end;
end;
CloseServiceHandle(SCManHandle);
end;
end;




end.



 
_toltec   (2003-02-22 02:08) [5]

Все спосибо, правда я сам разобрался, но все-равно спасибо.



Страницы: 1 вся ветка

Текущий архив: 2003.04.21;
Скачать: CL | DM;

Наверх




Память: 0.49 MB
Время: 0.02 c
14-67496
Hirara
2003-04-01 22:42
2003.04.21
Метод наискорейшего спуска


4-67615
{{{KOTOS}}}
2003-02-12 13:01
2003.04.21
как мне поймать клик мыши в windows а не в ФОрме?


14-67464
Карлсон
2003-04-03 22:38
2003.04.21
макулатура


6-67407
Reals
2003-02-25 19:46
2003.04.21
Клиент новостей (NNTP). Как читать русский текст (кирилицу).


1-67282
iNew
2003-04-11 09:00
2003.04.21
Как определить выделен текст в Edit или нет?