Closint processes

P

Peter

I have a VB 2008 program, AutoBackup3, converted from VB 6, to back up my
files, using Migo Backup Pro, & to do several manipulations with the
resulting backup files.

Migo Backup Pro is called using a statement:
Backup = Process.Start(PathFile, Arguments)
After the backup program is finished, it 'leaves behind' the three processes
listed in the the Dim procNameA() ... statement below.

When I execute the subroutine below, it executes just fine, except, none of
the three processes are actualluy being closed. They are still running
aftert my appplication, AutoBackup3, closes.

What am I doing wrong?

Subroutine Listing:
'Closes specified processes
Sub CloseProcesses2()

Dim procNameA() As String = {"NBKCtrl", "NSEngine", "NMSAccessU"}
Dim procName As String
Dim myProcesses As Process()
Dim myProcess As Process

Try

For Each procName In procNameA
' Get all instances of the named process running on the
local computer
myProcesses = Process.GetProcessesByName(procName)
If Not myProcesses Is Nothing Then
Debug.WriteLine("Number of instances = " &
myProcesses.Count)
For Each myProcess In myProcesses
If myProcess.MainWindowTitle <> "" Then
myProcess.CloseMainWindow()
End If
myProcess.Close()
Next
Else
Debug.WriteLine("Process " & procName & " not found")
End If
Next

Catch ex As Exception
Dim strProgram, strMsg As String
strProgram = "CloseProcesses2"
strMsg = "An error occurred during closing of processes." &
vbCrLf & vbCrLf _
& "Error Description: " & ex.Message
MsgBox(strMsg, vbExclamation + vbOKOnly, strProgram)
End Try

End Sub


Any Assistance will be appreciated.

Peter
 
M

Mattias Sjögren

What am I doing wrong?

Process.Close doesn't to anything to close the actual process, it just
invalidates the Process object instance (more or less the same as the
Dispose method). If Process.CloseMainWindow doesn't do what you need
(if there's no window to close or it doesn't make the application
exit) you're basically left with Process.Kill which is kind of an
extreme way to force a process to terminate with no opportunity to
clean up properly.



Mattias
 
P

Peter

Thxs, that clarifies things. I wish the help files would spell out those
things.
of the three apps I'm trying to kill, two don't have a main window. So, I
guess I'll have to use the Kill method.

Actually, Migo PCBackup Pro, the software I'm using, should close its own
apps as the backup process comes to an end, but they don't.

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top