11
votes

I wrote a batch script to execute after my installation that is made with Inno Setup. The problem is that I have the following command line for my service creation:

sc create MySQL start= auto DisplayName= MySQL binPath= "C:\MyApp\MySQL 5.5\bin\mysqld" --defaults-file="C:\MyApp\MySQL 5.5\my.ini"

The letters with accents are the problem of this code, I can't execute it if I open the bat file in cmd, but when I type the service is created normally. How can I fix that?

2
You could use AfterInstall and then Exec function or [Run] Filename: "{cmd}"; Parameters: "sc create MySQL start= auto DisplayName= MySQL binPath= ""C:\A Nova Solução Informática\MySQL 5.5\bin\mysqld"" --defaults-file=""C:\A Nova Solução Informática\MySQL 5.5\my.ini"""; Flags: runhiddenRobeN
Try to add CHCP 65001 at the beginning of your batch file and save it as UTF-8 without BOM. @Roben, or just [Run] section.TLama
@RobeN, your solution partially helped me, the problem is that after the instalation of the service, the cmd process stay opened and the instalation don't finalize itself.juniorgarcia

2 Answers

14
votes

Rather than calling SC directly, it's cleaner (and easier to deal with any errors or service dependencies) to use the API. Note that this example assumes that you're using ANSI Inno, but it's fairly straightforward to modify this for Unicode.

Personally, though, I prefer to build install/start/stop/uninstall commands into the service executable itself, making it self-registering. Obviously this isn't possible to do yourself for a third-party service, but you could check to see if it already supports something like this.

One final point is that you must not hard-code the path to a C: folder. You should be using {app} instead.

4
votes

You could try to add this command to [RUN] section (as TLama suggested) or create AfterInstall function in [CODE] section.

[Run] 
Filename: "{cmd}"; Parameters: "sc create MySQL start= auto DisplayName= MySQL 
binPath= ""C:\MyApp\MySQL 5.5\bin\mysqld"" 
--defaults-file=""C:\MyApp\MySQL 5.5\my.ini"""; 
Flags: runhidden