Форум: "Система";
Текущий архив: 2003.02.13;
Скачать: [xml.tar.bz2];
ВнизService Найти похожие ветки
← →
Senator (2002-12-10 11:46) [0]Подскажите, плз, как после инсталяции сервиса запустить его программно (в обработчике afterInstall) ??
← →
Chrome2002 (2002-12-11 13:12) [1]Единственное что можно посоветовать, так это заставить cmd выполнить команду net start "имя сервиса"
← →
Александр Спелицин (2002-12-13 00:35) [2]StartService
← →
Севостьянов Игорь (2002-12-13 11:01) [3]Может это поможет ?
library SrvStatus;
uses
//SharedMM,
SrvcStatus in "SrvcStatus.pas";
exports
GetServiceStateByName,
CheckServiceStateByName,
SetServiceStateByName;
begin
end.
unit SrvcStatus;
interface
uses WinSvc;
const
SERVICE_STATE_RUNING = 1;
SERVICE_STATE_STOPPED = 2;
SERVICE_STATE_ERROR = 3;
SERVICE_STATE_WARNING = 4;
type
THandle = LongWord;
var
FSCMHandle : THandle; { Handle to the Service Control Manager }
FServiceHandle : THandle; { Handle to the service }
FServiceStatus : TServiceStatus; { Status of the service }
function PrepareService(MachineName, ServiceName: string;
SCMAccess, ServiceAccess: Integer): Boolean;
function CloseService: Boolean;
function GetServiceState: Integer;
function GetServiceStateByName(const MachineName: string): Integer; stdcall;
function CheckServiceStateByName(const MachineName: string; NeedState: Integer): Boolean; stdcall;
function SetServiceStateByName(const MachineName: string; SetState: Integer): Boolean; stdcall;
implementation
function PrepareService(MachineName, ServiceName: string; SCMAccess, ServiceAccess: Integer): Boolean;
begin
FSCMHandle := OpenSCManager(PChar(MachineName), "ServicesActive", SCMAccess);
if FSCMHandle <> 0 then
FServiceHandle := OpenService(FSCMHandle, PChar(ServiceName), ServiceAccess);
Result := FServiceHandle <> 0;
end;
function CloseService: Boolean;
begin
Result := False;
if (FSCMHandle <> 0) and (FServiceHandle <> 0) then
Result := CloseServiceHandle(FServiceHandle) and CloseServiceHandle(FSCMHandle);
end;
function GetServiceState: Integer;
begin
Result := 0;
if QueryServiceStatus(FServiceHandle, FServiceStatus) then
Result := FServiceStatus.dwCurrentState;
end;
function ServiceStart: Boolean;
var
P : PChar;
begin
P := "";
Result := StartService(FServiceHandle, 0, P);
end;
function ServiceStop: Boolean;
begin
Result := ControlService(FServiceHandle, SERVICE_CONTROL_STOP, FServiceStatus);
end;
function ServiceContinue: Boolean;
begin
Result := ControlService(FServiceHandle, SERVICE_CONTROL_CONTINUE, FServiceStatus);
end;
function GetServiceStateByName(const MachineName: string): Integer; stdcall;
begin
Result := SERVICE_STATE_WARNING;
if PrepareService(MachineName, "Messenger",
SC_MANAGER_ENUMERATE_SERVICE,
SERVICE_QUERY_STATUS) then
begin
case GetServiceState of
SERVICE_START_PENDING,
SERVICE_RUNNING,
SERVICE_CONTINUE_PENDING: Result := SERVICE_STATE_RUNING;
SERVICE_STOPPED,
SERVICE_STOP_PENDING,
SERVICE_PAUSE_PENDING,
SERVICE_PAUSED: Result := SERVICE_STATE_STOPPED;
else Result := SERVICE_STATE_ERROR;
end;
CloseService;
end;
end;
function CheckServiceStateByName(const MachineName: string; NeedState: Integer): Boolean; stdcall;
begin
Result := False;
if PrepareService(MachineName, "Messenger",
SC_MANAGER_ENUMERATE_SERVICE,
SERVICE_QUERY_STATUS) then
begin
case NeedState of
SERVICE_STATE_RUNING: Result := GetServiceState = SERVICE_RUNNING;
SERVICE_STATE_STOPPED: Result := GetServiceState = SERVICE_STOPPED;
end;
CloseService;
end;
end;
function SetServiceStateByName(const MachineName: string; SetState: Integer): Boolean; stdcall;
var
State: Integer;
begin
Result := False;
if PrepareService(MachineName, "Messenger",
SC_MANAGER_ALL_ACCESS,
SERVICE_ALL_ACCESS) then
begin
State := GetServiceState;
case SetState of
SERVICE_STATE_STOPPED:
if State in [SERVICE_RUNNING,
SERVICE_PAUSED,
SERVICE_START_PENDING,
SERVICE_CONTINUE_PENDING] then Result := ServiceStop;
SERVICE_STATE_RUNING:
begin
if State in [SERVICE_STOPPED, SERVICE_STOP_PENDING] then Result := ServiceStart;
if State in [SERVICE_PAUSED, SERVICE_PAUSE_PENDING] then Result := ServiceContinue;
end;
end;
CloseService;
end;
end;
end.
http://delphi.mastak.ru/cgi-bin/download.pl?get=1038816841&n=0
Страницы: 1 вся ветка
Форум: "Система";
Текущий архив: 2003.02.13;
Скачать: [xml.tar.bz2];
Память: 0.46 MB
Время: 0.01 c