0

I am using Visual Studio Installer for my WPF Application.

My application is always running in the background.

When I want to install a newer version of the application the Installer says that the application file is in use and it will restart the Windows after installation.

How can I quit the application when the Installer starts so the application file won't be in use and I can prevent the need for restart?

Swati
  • 2,870
  • 7
  • 45
  • 87
Antti202
  • 3
  • 1

2 Answers2

0

You can add a custom action for your installer in Install

enter image description here

This custom action can first kill the running task using a shell script or a vb script. I can suggest your vb script to be somewhat like:

Dim oShell
Dim myApp

Set oShell = CreateObject("WScript.Shell")

'Find myApp in running processes'
for each Process in Service.InstancesOf ("Win32_Process")
if Process.Name = "myApp.exe" then
    myApp = Process
end if
next

'Exit myApp'
myApp.SendKeys "exit~"

You can store this as a .vbs file in your application and use it as a resource for your installer project.

praty
  • 535
  • 2
  • 9
  • @MickyD, edited my answer. If you have a better way please do suggest. – praty Aug 28 '17 at 10:04
  • Somehow Custom Actions run after the installation has been completed. Can't get it to run before. – Antti202 Aug 28 '17 at 10:25
  • @Antti202, [this thread](https://stackoverflow.com/questions/43588445/add-custom-action-of-installing-msi-before-the-setup-in-installer-project) may help you with that. It proposes to add a bootstrapper for your msi installer package. – praty Aug 28 '17 at 12:02
0

Not sure if this will be valid for you... I would try to get the hidden window of the running app and sending a message to close it. The related APIs are FindWindow and SendMessage. However, I don't know if you can code this in your installer. Good luck