0

I would like to install MySQL service after install in Inno Setup. There is already similar question here, but no solution there works for me.

If I use sc create like that in the solution, then after installation command promt just pop up, but doesn't do anything.

I tried modify command according some page, it works great in cmd:

sc create "MySQLSW" binpath= "\"C:\Program Files (x86)\Drevarska spolecnost\MySQL Server 5.6\bin\mysqld\" --defaults-file=\"C:\Program Files (x86)\Drevarska spolecnost\my.ini\" MySQLSW" DisplayName= "MySQLSW" start= "auto"

For Inno Setup it needs to be double quoted, so I tried this and few variants of it

[Run] 
Filename: "{cmd}"; Parameters: "sc create ""MySQLSW"" binpath= ""\""{app}\MySQL Server 5.6\bin\mysqld\"" --defaults-file=\""{app}\my.ini\"" MySQLSW"" DisplayName= ""MySQLSW"" start= ""auto""";

But cmd won't execute anything. Problem could be with that backslash, but I don't know the correct syntax.

I also tried add API from here and use following code, but there must be something wrong too, because it just pass installation, but won't create service.

procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssPostInstall then
  begin
    if IsServiceInstalled('MySQLSW') = false then begin
      if InstallService(ExpandConstant('{app}\MySQL Server 5.6\bin\mysqld.exe'),ExpandConstant('--defaults-file="{app}\my.ini"'),'MySQLSW','Needed for mysql database',SERVICE_WIN32_OWN_PROCESS,SERVICE_AUTO_START) = true then begin
        StartService('MySQLSW');
      end
    end
    else if IsServiceRunning('MySQLSW') then
        MsgBox('MySQLSW is running',mbInformation, MB_OK);
  end;
end;

I'm not much skilled in this yet, but I'm sure, there would be some misplaced quote somewhere, but I can't find it. Thanks in advance for help.

Community
  • 1
  • 1
zelvator
  • 25
  • 2
  • 4
  • Incidentally, the reason why your `[Run]` call didn't work is that you forgot the `/c` parameter to `{cmd}`. But using `{cmd}` was entirely unnecessary -- you could have just called sc directly. However the final solution of using the service API directly is better anyway. – Miral Apr 08 '13 at 20:57

1 Answers1

1

I have found at least one strange point.

InstallService definition by https://github.com/pgina/pgina/blob/master/Installer/scripts/services.iss:

function InstallService(FileName, ServiceName, DisplayName, Description : string;ServiceType,StartType :cardinal) : boolean;

Your call

InstallService(ExpandConstant('{app}\MySQL Server 5.6\bin\mysqld.exe'),ExpandConstant('--defaults-file="{app}\my.ini"'),'MySQLSW','Needed for mysql database',SERVICE_WIN32_OWN_PROCESS,SERVICE_AUTO_START)

Are you sure ServiceName may contain such things?

FileName - ExpandConstant('{app}\MySQL Server 5.6\bin\mysqld.exe')
ServiceName - ExpandConstant('--defaults-file="{app}\my.ini"')
DisplayName - 'MySQLSW'
Description - 'Needed for mysql database'
ServiceType - SERVICE_WIN32_OWN_PROCESS
StartType - SERVICE_AUTO_START

Try this

InstallService(ExpandConstant('"{app}\MySQL Server 5.6\bin\mysqld.exe"') + ExpandConstant(' --defaults-file="{app}\my.ini" MySQLSW'), 'MySQLSW' ,'MySQLSW','Needed for mysql database',SERVICE_WIN32_OWN_PROCESS,SERVICE_AUTO_START)
Andrey Volk
  • 3,513
  • 2
  • 17
  • 29
  • It is very good when an answer explain what's the source of the problem, but you may consider to include an example of how the correct way to do it should look. – jachguate Apr 06 '13 at 16:20
  • I wasn't sure, where to put that --defaults-file, on some page they used it in that ServiceName, so I was assumming it would be correct and searching problem somewhere else... Neverthless it is working now, I just needed to add name of service behind --defauls-file: ExpandConstant(' --defaults-file="{app}\my.ini" MySQLSW') Now it's perfect. Thank you very much. – zelvator Apr 06 '13 at 17:08
  • You might want to use proper function prototypes from [this post](http://stackoverflow.com/a/15235687/960757). They're even ANSI and Unicode InnoSetup friendly. – TLama Apr 06 '13 at 19:28