I made a simple "restarter" app... However, I need to close multiple instances of an application. For example, if I have three windows of paint, or three windows of Word open, how do I check if it is still open before I open a new instance?
Here is my current code:
Module RestartCheck Sub Main() Dim FormName As String FormName = "TestMonkey" 'close paint Dim proc = Process.GetProcessesByName("PaintDotNet") For i As Integer = 0 To proc.Count - 1 proc(i).CloseMainWindow() Next i 'wait for five seconds Threading.Thread.Sleep(5000) 'open paint again Dim sAppName As String, sAppPath As String sAppName = "PaintDotNet" sAppPath = "C:\Program Files\Paint.NET\PaintDotNet.exe" Shell(sAppPath, vbNormalFocus) End Sub End Module
The way I close paint is not working. It only closes ONE instance of paint, if I have multiple open. So I would like to add a check.
Should I do something like this?
If My.Application.OpenForms.Item(i).Text = FormName Then
'(keep a count here)
Sorry, new to VB. This may be a silly question. Thanks for your help.