How do I detect and stop a process?AnswerWhen updating an installation it is recommended to stop the installed application before overwriting its files. Usually this is managed automatically by Windows Installer through the "FilesInUse" and "MsiRMFilesInUse" dialogs, but you can close your application whenever you want through a custom action. Detect if a process is runningYou can detect if a process is running by using a VBScript custom action which looks like this: Dim objWMIService, objProcess, colProcess
Dim strComputer
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery ("Select * from Win32_Process")
Session.Property("PROCESS")="NOT RUNNING"
For Each objProcess in colProcess
if objProcess.Name = "AdvancedInstaller.exe" then
Session.Property("PROCESS")="RUNNING"
End If
NextThis code can be pasted in a .VBS file which can be added as an Attached custom action under the "InstallExecuteSequence" -> "FindRelatedProducts" standard action. You can see this standard action by using the "Show Standard Action" button on the toolbar of the Custom Actions page.
The above custom actions will search for the process named 'AdvancedInstaller.exe' (this process is running when Advanced Installer is opened). Based on the result of this search, the custom action sets the property PROCESS to RUNNING or NOT RUNNING. You can use this property as a custom launch condition for the installation package in order to stop the installation if the main application is running. Stop a processThe custom action which detects if a process is running can be modified to stop a process if it detects it: Dim objWMIService, objProcess, colProcess
Dim strComputer
Dim objname
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
strProcessKill = "'AdvancedInstaller.exe'"
Set colProcess = objWMIService.ExecQuery("Select * from Win32_Process Where Name = " & strProcessKill)
For Each objProcess in colProcess
objname = objProcess.Name
If objProcess.Name = "AdvancedInstaller.exe" then
objProcess.Terminate()
End If
Next You can add this code in a .VBS file and add the file as an Attached custom action. This custom action can be scheduled under a standard action which is executed before the process needs to be terminated.
On Windows Vista these custom actions can run only as Deferred with no impersonation. In this case, you can use the Action Data field in the Custom Action Properties page to pass the "PROCESS" (or another) property to the custom action. The value in the "Action Data" field can be retrieved inside the custom action from the CustomActionData property (for example Session.Property("CustomActionData")). | |
|
| Privacy Policy | Windows Installer | Search Engine Ranking | Link Analyzer | ||
| © 2002 - 2008 Caphyon Ltd. Trademarks belong to their respective owners. All rights reserved. | ||