Inno Setup Execute a batch file before [Files] section

烂漫一生 提交于 2019-11-30 19:42:32

If it needs to be done at the beginning of the setup, use Exec() in the PrepareToInstall() or CurStepChanged(ssInstall) event functions. These are both after the user has said "go ahead, install" but before anything else. PrepareToInstall() also allows you to cancel the install with a nice warning.

If the file needs to be extracted from the setup first, then you can preceed it with ExtractTemporaryFile()

Alex K.

You can use the InitializeSetup event + some pascal scripting.

See; How to run a file before setup with Inno Setup

Not mentioned in that example; to get the file from the installer you would use ExtractTemporaryFile('your.bat') then Exec(ExpandConstant('{tmp}\your.bat ... to run it.

Continuing Deanna's great answer, code example:

[code]
function PrepareToInstall(var NeedsRestart: Boolean): String;
var
   ResultCode: integer;
begin
   Exec(ExpandConstant('{app}\serviceDeployment\unInstallService.bat'), '', '', SW_SHOW, ewWaitUntilTerminated, ResultCode)
end;

this code always returns an empty string, which tells the setup to continue. In case you want to stop setup (in some error cases) you need to return a non empty string and it will be displayed to the user (and setup will be stopped).

In order to return an error string add this line in PrepareToInstall's:

Result := 'Your Error Description';
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!