Ruben
Posts: 57
Joined: Fri Apr 10, 2015 2:35 pm

Run WMIC from Custom Action before RemoveFiles

Hello Team and Users,

In our MSI installer, we try to run that WMIC command early, before RemoveFiles happens:

Code: Select all

wmic Path win32_process Where "Caption Like '%%java%%.exe%%' AND CommandLine Like '%%OurProgramName%%'" Call Terminate
The purpose is to kill instances of our software. Otherwise, msiexec will fail to replace our program files.
(Our software may be started by different users on that machine, that's even likely.)


What we tried:


1. Run the WMIC from a Batch file
Failed because Batch cannot run as "Attached File".

2. Run the WMIC from a VBS file
The VBS can be run as attached file. OK, we might eventually succeed in running it before RemoveFiles happens.
Still Failed because the VBS would require a line like

Code: Select all

Set objShell = WScript.CreateObject ("WScript.shell")
[/size]
to run the WMIC command. Bad luck, VBS in an MSI installer has no "WScript" object.


I ran out of ideas. How to kill our processes to allow removal of the program files ?

Thank you,
Ruben
Sorin
Posts: 663
Joined: Mon May 08, 2017 1:03 pm

Re: Run WMIC from Custom Action before RemoveFiles

Hello,

You could use our predefined "Terminate Process" custom action. You should schedule it before "Wizard Dialogs Stage" -> "Searches". It should also be dragged before "Install Execution Stage" -> "Searches" while the SHIFT key is pressed to make sure it runs even if there is no UI. In this case the custom action should use the "Execute only once if present in both sequence tables" option in the Custom Action Properties page.

Please take a look on our article : How to detect or stop a process

Regarding the methods you've mentioned, you could add the batch as a temporary file and use "Launch File" custom action. In this way the bat is removed after the installation is finished.

Best regards,
Sorin
Sorin Stefan - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Ruben
Posts: 57
Joined: Fri Apr 10, 2015 2:35 pm

Re: Run WMIC from Custom Action before RemoveFiles

Hello Sorin,

Sorry. I still can't see a satisfying solution.
a) The "Terminate Process" action does not work since it stops processes by name only. Our process is "javaw.exe" - this is far too unspecific.


b) The temporary files concept is great. I tested and it does nearly succeed.
What we tried is:

1.add a Batch file as temporary file

2.Run it with a "Launch file" Custom Action. I placed the Action in the Install Execution Stage, after "Preparing", with "Run Immediately."
I choose "Run as Administrator". Otherwise, processes of other users keep running.

Unfortunately, this solution is annoying for the users.
When installing, the user is asked twice for the admin password. This solution would work very well - if only the user had a "normal" installation with the admin password asked once.
Eventually, I did it wrong...?

Could you have a look whether there's a solution which feels "smooth" for the user ?
Thank you very much,
Ruben
Sorin
Posts: 663
Joined: Mon May 08, 2017 1:03 pm

Re: Run WMIC from Custom Action before RemoveFiles

Hello Ruben,
Unfortunately, this solution is annoying for the users.
When installing, the user is asked twice for the admin password
In order to overcome this double elevation prompt you could enable "Run as administrator" option from "Install Parameters" page and uncheck the "Run as admin" option from your Launch File custom action.

In this way the install process will run elevated from the beginning to the end and the launch file custom action will run with elevated privileges. This option will change the build type to EXE.

Best regards,
Sorin
Sorin Stefan - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”