none
Shut down running processes at the time of upgrade to avoid showing "FilesInUse" dialog in VS 2019 Installer Projects RRS feed

  • Question

  • Hi,

    I need to be able to shut down running applications [Including a windows service] during an upgrade without asking the user to stop the applications. However, I cant figure out how to do it with custom actions. The code to shut down the service is in the custom action, but the custom action gets called after the files in use dialog, irrespective of what I do.

    As per this post,

    https://social.msdn.microsoft.com/Forums/windows/en-US/15f95e36-92c4-4006-a15b-85818c80f739/how-to-kill-the-application-process-in-use-before-upgrade-using-setup-projects?forum=winformssetup 

     I see that Custom actions in a VS setup project wont work because they all run after the files have all been installed.

    So, Is what I am trying to do really possible? I saw a few posts that seem to say it is. But I cant figure out how.

    The post at SO

    https://stackoverflow.com/questions/50917062/windows-installer-avoid-fileinuse-dialog-box-when-installing-a-package

    seems to say

    Graceful Shutdown Custom Action: If you make your application capable of graceful shutdown (restart manager-style), then you can trigger such a shutdown yourself as well (easiest for user context processes) via an immediate mode custom action (in case Restart Manager is disabled by policy - look out for timing and timeout issues though - especially for silent running - "deadlock").
    And

    https://stackoverflow.com/questions/31633696/terminating-process-in-customaction ]

    seem to say that it is possible to do so with custom actions

    I tried setting sequence numbers but the custom actions are not executed before InstallValidate at all. And even if I try to disable InstallValidate [by putting a condition that will evaluate to FALSE], the files in use dialog still pops up. I have also added the property MSIRESTARTMANAGERCONTROL and set it to "Disable"

    In the screenshot, the CA with condition "Installed AND UPGRADINGPRODUCTCODE" is the one I want to run at the time of upgrade.

    Please helpOrca Screenshot

    Wednesday, June 12, 2019 3:03 AM

Answers

  • I created a VS Installer project that installed a service executable and an MFC application.

    After the VS Installer project had created the msi, I ran a post-build event to add entries to the ServiceControl and the ServiceInstall tables to handle the service related tasks.

    To avoid the FileInUse dialog I created a Type 1 Custom Action.  This was a small DLL that for test purposes would find the window handle of the MFC application and send it a WM_CLOSE message.  The post-build event added the DLL to the Binary Table, added a custom action to the CustomAction table with the Type field set to msidbCustomActionTypeDll | msidbCustomActionTypeFirstSequence and then added the custom action to the InstallUISequence table with sequence 960 and to the InstallExecuteSequence table with sequence 1300.

    Running the installer installed the binaries and also started the service.  Then I started the MFC application.  While the MFC application and the service were both running I did two types of tests -- uninstall and upgrade.  In my limited testing the custom action closed the MFC application in a timely manner and the FileInUse dialog never appeared. 


    Footnote - I don't have VS2019 installed, the above was done with VS2015
    • Edited by RLWA32 Saturday, June 15, 2019 7:56 PM
    • Marked as answer by Sagar R. Kapadia Sunday, June 16, 2019 2:58 AM
    Saturday, June 15, 2019 6:51 PM
  • Monday, June 17, 2019 10:39 AM

All replies

  • Hi,

    Here I found a thread about "stop the service" maybe you can refer to.

    https://stackoverflow.com/a/10541653/8335151.

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, June 12, 2019 7:08 AM
    Moderator
  • Thanks for the reply Kyle. 

    However, I need to know how to sequence the custom action so that it runs before the upgrade process starts. At present, the files in use dialog is shown before any custom action runs. This is the specific issue I am facing. I am unable to figure out where to sequence the custom action which will shut down processes, and what conditions to put on it. 

    Sagar

    Wednesday, June 12, 2019 7:50 AM
  • Hi,

    Where did you confirm there is a new version to update? Have you tried to shut down the service before checking for updates?

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, June 14, 2019 9:58 AM
    Moderator
  • Hi,

    Where did you confirm there is a new version to update? Have you tried to shut down the service before checking for updates?

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    I did not understand the question "Where did you confirm there is a new version to update?"

    I tried various positions for the custom actions. But either they got ignored, or there was error 2762 "The action must be scheduled between InstallInitialize and InstallFinalize" . I also tried to disable InstallValidate, and even deleted that row. But it still got called.

    So the FilesInUse dialog appears. Also, I understand that it is not possible to integrate with RestartManager if we use VS Installer Projects, because the MSIRMFIlesInUse dialog cannot be added.


    Friday, June 14, 2019 2:25 PM
  • For your service I suggest using the Service Control and the Service install tables instead of a custom action.  If you use these tables, the Windows installer can be instructed to shutdown/restart/delete services during the install and uninstall. See https://docs.microsoft.com/en-us/windows/desktop/msi/servicecontrol-table and https://docs.microsoft.com/en-us/windows/desktop/msi/serviceinstall-table

    And since you want to shutdown a user application without intervention you can use an immediate mode custom action.  See https://docs.microsoft.com/en-us/windows/desktop/msi/custom-action-execution-scheduling-options and also see https://docs.microsoft.com/en-us/windows/desktop/msi/summary-list-of-all-custom-action-types. Note that types 1, 2, 5 and 6 use binary data stored in the msi.


    You can accomplish these things with Orca or write a program or script to make the changes to the msi created by a VS Installer project.
    • Edited by RLWA32 Friday, June 14, 2019 6:01 PM
    Friday, June 14, 2019 6:00 PM
  • For your service I suggest using the Service Control and the Service install tables instead of a custom action.  If you use these tables, the Windows installer can be instructed to shutdown/restart/delete services during the install and uninstall. See https://docs.microsoft.com/en-us/windows/desktop/msi/servicecontrol-table and https://docs.microsoft.com/en-us/windows/desktop/msi/serviceinstall-table

    And since you want to shutdown a user application without intervention you can use an immediate mode custom action.  See https://docs.microsoft.com/en-us/windows/desktop/msi/custom-action-execution-scheduling-options and also see https://docs.microsoft.com/en-us/windows/desktop/msi/summary-list-of-all-custom-action-types. Note that types 1, 2, 5 and 6 use binary data stored in the msi.


    You can accomplish these things with Orca or write a program or script to make the changes to the msi created by a VS Installer project.

    Thanks for the reply RLWA32. I already use the service control and service tables to control the starting and stopping of the services. However, I do not understand immediate mode custom action. What do I need to do to make an action immediate? I tried changing the sequence, but that did not work. One of the links above says the type of the custom action in the custom action table needs to be changed to an appropriate value. 

    But should the type be 

    (default)

    Hexadecimal: 0x00000000

    Decimal: 0

    or 

    Custom Action Type 34EXE file having a path referencing a directory.

    Thanks,

    Sagar

    34

    Key to Directory table. This is the working directory for execution.

    Saturday, June 15, 2019 3:36 PM
  • I created a VS Installer project that installed a service executable and an MFC application.

    After the VS Installer project had created the msi, I ran a post-build event to add entries to the ServiceControl and the ServiceInstall tables to handle the service related tasks.

    To avoid the FileInUse dialog I created a Type 1 Custom Action.  This was a small DLL that for test purposes would find the window handle of the MFC application and send it a WM_CLOSE message.  The post-build event added the DLL to the Binary Table, added a custom action to the CustomAction table with the Type field set to msidbCustomActionTypeDll | msidbCustomActionTypeFirstSequence and then added the custom action to the InstallUISequence table with sequence 960 and to the InstallExecuteSequence table with sequence 1300.

    Running the installer installed the binaries and also started the service.  Then I started the MFC application.  While the MFC application and the service were both running I did two types of tests -- uninstall and upgrade.  In my limited testing the custom action closed the MFC application in a timely manner and the FileInUse dialog never appeared. 


    Footnote - I don't have VS2019 installed, the above was done with VS2015
    • Edited by RLWA32 Saturday, June 15, 2019 7:56 PM
    • Marked as answer by Sagar R. Kapadia Sunday, June 16, 2019 2:58 AM
    Saturday, June 15, 2019 6:51 PM
  • Thanks a lot for the answer , RLWA32. It resolved my issue. However, for the condition in the InstallExecuteSequence table, I had to use 'NOT REMOVE' instead of 'UPGRADINGPRODUCTCODE'. The later evaluates to FALSE. Apart from that, it works perfectly. I still need to test it properly, though. 

    Sunday, June 16, 2019 3:00 AM
  • RLWA32,

    How do I embed a dll into binary table of the msi by code and by a custom action? I can do this manually using orca, but I need to automate it.

    Thanks,

    Sagar

    Monday, June 17, 2019 7:07 AM
  • Monday, June 17, 2019 10:39 AM
  • Thanks, RLWA32
    Monday, June 17, 2019 11:17 AM
  • One thing to keep in mind is that the Custom Action dll must not have any dependencies that will not be present on the target system.
    Monday, June 17, 2019 12:13 PM