2013-10-11 176 views
1

在Inno啓動我的應用程序後,我希望Inno安裝2個服務,並在Windows服務列表中安裝文件夾的屬性。Inno安裝程序編譯器:如何安裝服務

我已經安裝了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

我需要查看原始代碼。或者,我會發布一系列關於如何安裝,控制和卸載服務的問答。 [我現在忙着去做...] – TLama

回答

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 /?」在窗口中。

+0

避免儘可能地使用命令行工具。始終更喜歡本機Windows API解決方案。在這種情況下,當出現問題時,您無法控制情況。 – TLama

+0

謝謝,我是綠色的手,我會繼續學習INNO SETUP。 – LEo

相關問題