While performing installation, sometimes, we need to check whether the instance of a particualr program exist or not.
I got this problem while installing my plug-in. Outlook should be closed before the installation starts. So, I need to check for the existance of Outlook before installation. After so many days and lot of efforts, finally I have got a solution for this.
While Process.GetProcessesByName(“Outlook”).Length > 0
MsgBox(“Outlook is still open. Please close it”)
End While
This loop will iterate until the Outlook is closed.
We can also close a program forcibly using the following code.
Dim myProcesses() As Process
Dim instance As Process
myProcesses = Process.GetProcessesByName(“Outlook”)
For Each instance In myProcesses
instance.CloseMainWindow() ‘ This will close the application that is running
Next