I've created a working installer package in which all files are bundled into a single exe. I have created custom actions to stop two processes associated with my application, in case a previous version is running: the wrapped "Java Product" exe produced by Advanced Installer (Java edition) and a native C++ utility that is installed as part of my installer package. I stop these processes at the beginning of a silent/unattended or normal (UI) install (any install) to prevent Windows' "FilesInUse" dialog from appearing. Such a dialog is fine when installed manually (with a UI) but this package will eventually be pushed within my agency via SCCM so a silent, unattended install is also a must.
The problem: the C++ utility process is stopped successfully (before the FilesInUse dialog appears, so I know I have the custom actions in the right sequence) but the Java wrapper exe process produced by Advanced Installer is not be stopped. I have tried enclosing the process name that appears in task manager within quotes on the "Terminate Process" custom action, but it still isn't being terminated. My guess is that the process name appearing in task manager isn't the true process name, as identified by Windows itself. I'm going to try using a utility such as "Process Explorer" from TechNet to get more details but I though I would ask up front here if it should be possible to terminate the Java Product's native wrapper process using a Custom Action in this way.
Would still like to hear from anyone, but the reason for the failure to stop the process seems to be because Advanced Installer's native Java wrapper (exe) ignores termination signals. I used the "taskkill" utility included with Windows 7 to test. I had it send a termination command to my wrapped Java exe. The signal was sent but the process was not stopped. Forcing the process to terminate (using taskkill utilities "/F" option) did successfully stop the process. So unless there is another suggestion I will need to use the "Launch Attached File" custom action to launch a C++ utility file that I will included in the MSI (but not install) for the purpose of forcibly stopping the wrapped process... since I don't know how I feel about relying on utilities included with Windows (cmd.exe, taskkill, etc.).
I've tested the scenario, but I cannot replicate the behavior. Can you please send us the .aip (project file) to support at advancedinstaller dot com so we can test and investigate this?
I apologize for being away from the forum for so long. I also need to apologize for this post in which I suggested that AI's native Java wrapper was not passing termination signals. These comments of mine were indicative of a below-par understanding of window communications on Microsoft operating systems. There is no problem with AI's wrapper.
The workarounds necessary are Java/Windows related and have nothing to do with Advanced Installer.
I'm still working out how to have a command or message sent to all app instances to tell them to shut down gracefully (there could be at most one instance of my app for each interactive user session) and I therefore still have the installer package using a "Taskkill.exe /F" command to forcibly terminate all instances (across all sessions) during an uninstall or upgrade.
For enabling the wrapped Java Product to detect Windows session termination and gracefully shut down before exit, I had to fall back to the use of Win32 functions through use of JNI (Java Native Interface). In short, what my testing found was the Oracle JVM will begin to shut down the moment it receives a "WM_QUERYENDSESSION" message broadcast from a Windows OS. Often, this does not leave enough time for shutdown hooks (Java threads used to conduct cleanup operations as the program exits) to complete execution of their code. This observed behavior is against Microsoft recommendations, which suggest that a program should immediately return a value of "true" for such messages but not actually begin to shut down until a "WM_ENDSESSION" message is received. Ultimately I had to use JNI native code to intercept the "WM_QUERYENDSESSION" message (preventing it from reaching the JFrame's underlying WndProc function through use of a custom, stand-in WndProc method) until I had gracefully shut down background worker threads and handled cleanup tasks. The custom WndProc function is then freed to respond to the OS' "WM_QUERYENDSESSION" message, flow control returns to the Java code, and the JVM subsequently shuts itself down (as fast as it would like).
<Addition>
Forgot to mention the reason why I originally suspected a bug with AI's wrapper (an improper jump to a conclusion on my part)...
My Java program "minimizes" to an icon in the system tray when the main JFrame's close button is clicked. When I issued a request-to-terminate command using "Taskkill.exe" (without the "/F" option) I noticed my Java app refused to shut down. Additional testing revealed this only happened if my app had been "restored" from the system tray and then sent back there at least once. The app starts as this "minimized" tray icon and the app would properly respond to a request to shutdown upon initial startup, but not if the JFrame was "restored" and subsequently sent back to the system tray. The problem is Java related - more testing would be needed to confirm the exact reason, but it seems that once the JFrame has been made visible and then invisible again, and an icon has been added to the system tray, there will be a hang on the EDT (event dispatch thread) when the JVM attempts to close the app. I found one or two posts online describing this same behavior/problem but no solution was given. The workaround is to never set the visibility of the JFrame to false after is had been made visible for the first time. Rather, hiding can be simulated by minimizing the JFrame to the taskbar and using a Win32 command (JNI solution) to remove the application's "tab" from the taskbar. I have since handled this behavior using JNI code that tied into a custom Java event for determining the reason for a JFrame's closure. The event can differentiate between a closing of the JFrame initiated by a session termination, activation of the close button by a mouse click, a mnemonic, or a system accelerator.
Last edited by jeffb on Wed Apr 23, 2014 12:10 pm, edited 5 times in total.
I'm glad you got this working. Also, thank you for posting your insights onto this matter. For certain this info will help future users in the same situation.
FOLLOW US
Get the latest news in Application Packaging