Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Система";
Текущий архив: 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
1-38333
anaTolik
2003-02-03 18:00
2003.02.13
Загрузка проекта.


14-38471
Jakommo
2003-01-29 12:58
2003.02.13
Свой Shell как средство предохранения от юзверей.


4-38644
Михаил
2003-01-03 22:13
2003.02.13
Сообщения внутри приложения


4-38624
Nikolay Enby
2002-12-30 21:26
2003.02.13
Подскажите, Мастера!


3-38117
78125
2003-01-28 09:56
2003.02.13
Как перейти к конкретной записи





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский