MSI: An Application is running during silent update - windows

I have an application that was installed as MSI package, I have next version of application that I plan to install in silent mode by special program.
When application is running I catch an issue: not all components of application installed
immediately, some of them will be really ready only after reboot. And I get unstable application.
I can check - is application running and wait until it closed, but I can't check the situation when user click on shortcut during silent installation.
How I can avoid this? Can I lock application during installation?

I suggest implementing Restart Manager support. Vista or later will attempt to shut down your application via the Restart Manager, you can decide how to handle it within your application (prompt user, autosave, something else, etc).
You won't catch the situation where the user starts the application during update, but it will handle multi-user sessions more gracefully than your custom code will.

Related

Stop a Windows service on re-installation and uninstallation in Inno Setup

I have an installer that starts a service on completion of installation. It stops and deletes the service on uninstallation it stops and deletes the service. After a successful installation of the app if I try to run the installer again it throws an error saying 'Setup has detected that application is already running'. How can I stop the service before installation happens?
Inno Setup reports that, only if you set AppMutex directive.
If you do not want the installer to detect that the application (service) is running, do not set the directive.
If you want to stop the application (service) before the detection, you can do it in InitializeSetup event function in installer, and using InitializeUninstall in uninstaller. Though note that making changes to user's machine before the user confirms anything, is not the right thing to do.

How does Windows Installer close an application during uninstall?

When uninstalling my application, it attempts to stop it if it's running:
Sadly, the automatically closing doesn't really work and it displays this error:
My applications disappear, the windows, the tray bar icon, they are all gone. But I can still see them in the process list.
I'm guessing Windows sends a signal to the applications to exit gracefully and the UI does so, but there's some lingering thread preventing the processes from terminating.
How does Windows Installer close an application during uninstall?
Once I know this I want to simulate it while debugging my app to see what's going on. Is this a sound plan?
Since Windows Vista, Windows Installer will leverage the Restart Manager to identify, close, and restart applications. Microsoft's documentation on Using Restart Manager, and in particular Using Restart Manager with a Primary Installer should be a solid starting point for implementing a test harness. Your applications and services should instead follow the Guidelines for Applications and Services.
The Guidelines for Applications discuss the messages sent to your application by the restart manager; services are restarted through the service control manager. In theory you could simulate the restart manager at that level, but I suspect you'd be better served by invoking the real thing, registering a carefully chosen list of resources to target just your application, if possible.

Restart Windows service when not respond

A legacy Service that I work is freezing due to database issues. And I'm looking for a simpler solution than fixing it.
In Aplication Form Version (Delphi), Windows recognize and show message that application is not responding.
Can Windows recognize when a service is not responding and restart the service?
In Service Properties the Recovery is only for failures.
In Aplication Form Version (Delphi), Windows recognize and show message that application is not responding.
Only if the main UI thread is blocked, but you shouldn't ever do anything in the main UI thread that can block it. Bad code design.
Can Windows recognize when a service is not responding and restart the service?
Not automatically, no. You need to fix your database code so it doesn't freeze up anymore in the first place. If that is not an option (which I highly doubt) then you will have to write a separate watchdog thread/process to monitor your code/service and kill it if it freezes up. If you kill the entire service, then Windows failure actions can be used to restart it.

Wix update - How can I restart my service but no other apps that are using my dll?

I have created an installer and I put out the update every now and then. FYI, my program has two parts: service application and dll. Some of other client applications use my dll and my service application runs constantly.
Because some of client applications use my dll, if I run the update, restart manager restart those client apps but I would like to make sure that they do not restart so I disabled restart manager by setting MSIRESTARTMANAGERCONTROL to be 'Disable' in my wix script.
So this prevents other client apps from restarting and that is great. But the side effect of it is that my service application does not restart either after the update procedure.
So basically my question is that I would like to find a way to prevent other client apps from restarting but I want to make sure that my service does restart after the update.
What would you recommend? Any advice will be appreciated.
You need to postprocess the MSI package emitted by your setup build. You will need to add entries to the ServiceControl table so that Windows Installer will stop the service when your component is installed and then start it up again after the new DLL is installed. You'll also need to ensure that the StopServices and StartService actions are scheduled in the InstallExecuteSequence table.
You'll need to use the wirunsql.vbs tool to run the relevant INSERT queries to add the necessary records.

Windows installer - prevent overriding a dll

I’m creating a setup project (Windows installer) in vs2010. When the user install it for the 1st time – everything is working just fine, but when the user try to upgrade the old application that’s running prevent of coping the new dlls to the installed folder.
How to show a user a dialog box that force him to shut down an application that prevent the installer from override a dll?
You need to check if a process with the name of your executable is running.
Then you can either abort the installation, ask the user to shut down the process or shut it down for them.
If you go for the second option you'll need to double check that they actually have shut it down before proceeding.

Resources