Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

When CloseApplications=force InnoSetup does not manage to close service before copying files

73 views
Skip to first unread message

Mail Torent

unread,
Feb 21, 2025, 5:55:36 AMFeb 21
to innosetup
Hello,
I have an installer which also setups windows service for background jobs.
When updating, prompt to close application appears and shows that service.

When CloseApplications=true  (by default), installer sucessfully kills the service in time before installing.

When CloseApplications=force, installer fails on Install window, and you need to click "Try again".

This does not happen randomly, it happens everytime. Looks like with force setup does not wait for closing of files?
This is how I setup the service:

[Run]
; Register the Windows service
Filename: "{cmd}"; Parameters: "/C sc create ABC.MyService binPath=""{app}\ABC.MyService.exe"" start= auto"; Flags: runhidden

; Start the service after installation
Filename: "{cmd}"; Parameters: "/C sc start ABC.MyService"; Flags: runhidden

[UninstallRun]
; Stop the service before uninstalling
Filename: "{cmd}"; Parameters: "/C sc stop ABC.MyService"; Flags: runhidden; RunOnceId: "Stop ABC Print Service"

; Delete the service during uninstallation
Filename: "{cmd}"; Parameters: "/C sc delete ABC.MyService"; Flags: runhidden; RunOnceId: "Delete ABC Print Service"

BTW, is there an option to hide that step from user and just force closing apps?
I thought force would do so, but looking at documentation there is not really a difference between yes and force.
 I did it in function PrepareToInstall(var NeedsRestart: Boolean): String; but maybe there is better option?

Regards
AW

Martijn Laan

unread,
Feb 21, 2025, 9:46:08 AMFeb 21
to inno...@googlegroups.com
Hi,

Op 21-2-2025 om 09:34 schreef Mail Torent:
is there an option to hide that step from user and just force closing apps?

I don't think so.


I thought force would do so, but looking at documentation there is not really a difference between yes and force.

All of the detection and closing and restarting is done bij Windows' Restart Manager. The difference between yes and force is that force passes RmForceShutdown to Restart Manager's RmShutdown and yes does not. See https://learn.microsoft.com/en-us/windows/win32/api/restartmanager/nf-restartmanager-rmshutdown

Greetings,
Martijn

Gavin Lambert

unread,
Feb 23, 2025, 5:17:52 PMFeb 23
to innosetup
On Friday, February 21, 2025 at 11:55:36 PM UTC+13 Mail Torent wrote:
BTW, is there an option to hide that step from user and just force closing apps?
I thought force would do so, but looking at documentation there is not really a difference between yes and force.
 I did it in function PrepareToInstall(var NeedsRestart: Boolean): String; but maybe there is better option?

The recommended approach is to gracefully stop the service from PrepareToInstall, as this occurs prior to the restart manager checks.  You can either use "net stop" or use the service manager API (though the latter requires extra steps to wait for it to stop).  Do not use "sc stop" as this does not wait for the service to actually stop. 
Reply all
Reply to author
Forward
0 new messages