Inno Setup Compiler:如何安装服务

时间:2013-10-11 10:10:17

标签: inno-setup

在Inno安装我的应用程序之后,我希望Inno在Windows服务列表中安装具有安装文件夹属性的2项服务。

我已经安装了wamp,我想为apachenew service for mysql`添加新服务

apacheServiceInstallParams = -n wampapachec -k install

mysqlServiceInstallParams = --install-manual wampmysqldc

function InstallService(const FileName, ServiceName, 
  DisplayName: string; ServiceType, StartType: DWORD): Boolean;
var
  ManagerHandle: SC_HANDLE;
  ServiceHandle: SC_HANDLE;
begin
  Result := False;
  ManagerHandle := OpenSCManager('', '', SC_MANAGER_ALL_ACCESS);
  if ManagerHandle <> 0 then
  begin
    try
      ServiceHandle := CreateService(ManagerHandle, ServiceName, 
        DisplayName, SERVICE_ALL_ACCESS, ServiceType, StartType,
        SERVICE_ERROR_IGNORE, FileName, '', 0, '', '', '');
      if ServiceHandle <> 0 then
      begin
        Result := True;
        CloseServiceHandle(ServiceHandle);
      end
      else
        MsgBox(SysErrorMessage(DLLGetLastError), mbError, MB_OK);
    finally
      CloseServiceHandle(ManagerHandle);
    end;
  end
  else
    MsgBox(SysErrorMessage(DLLGetLastError), mbError, MB_OK);
end;

procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssPostInstall then
  begin
    if InstallService(ExpandConstant('{app}\bin\aoache\apache2.2.22\bin\httpd.exe'),
      'wampapachecow',
      'MySQL', SERVICE_WIN32_SHARE_PROCESS, SERVICE_AUTO_START)
    then
      MsgBox('MySql Service installation succeeded!', mbInformation, MB_OK);
    if InstallService(ExpandConstant('{app}\bin\mysql\mysql5.5.24\bin\mysqld.exe'),
      'wampmysqldcow',
      'MySQL', SERVICE_WIN32_SHARE_PROCESS, SERVICE_AUTO_START)
    then
      MsgBox('MySql Service installation succeeded!', mbInformation, MB_OK);
  end;
end;

我不明白的地方:

我喜欢这样:

InstallService(ExpandConstant('{app}\bin\aoache\apache2.2.22\bin\httpd.exe'),
      'wampapachecow',
      'MySQL', SERVICE_WIN32_SHARE_PROCESS, SERVICE_AUTO_START)

它应该是这样的吗?

InstallService(ExpandConstant('{app}\MySQL 5.5\bin\mysqld.exe'),
      ExpandConstant('--defaults-file="{app}\MySQL 5.5\my.ini"'),
      'MySQL', SERVICE_WIN32_SHARE_PROCESS, SERVICE_AUTO_START)

请解释第二个参数:

'wampapachecow'ExpandConstant('--defaults-file="{app}\MySQL 5.5\my.ini"')

1 个答案:

答案 0 :(得分:0)

您可以使用以下代码创建服务,服务将自动启动。

// create a system service with windows command “sc”
DosCmd := '/C '+'sc create "WCF" binPath= "'+ExpandConstant('{app}\WCF.exe' \
  type= share start= auto DisplayName= "WCF"'+' obj= '+UserName+' password= '+Passwd;
Exec(ExpandConstant('{cmd}'),DosCmd, '',  SW_HIDE,ewWaitUntilTerminated, ResultCode);

然后,WCF服务将自动启动。要获得更多帮助,请运行“sc /?”在窗户。