1

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

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

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"')

4

1 回答 1

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 /?” 在窗户里。

于 2014-07-23T03:08:16.487 回答