Hi There,
I have searched this site for "closing processes" and found some great stuff.
I copied and changed some code that I found and have come up with the following function.
The problem is that it works great if it finds what it's looking for. If "Word" is not running than I get the following error:
Run-time exception thrown: System.ComponentModel.Win32Exception - Unable to enumerate the process modules.
I hope it's just something small that I'm missing.
Thanks for your time.
I have searched this site for "closing processes" and found some great stuff.
I copied and changed some code that I found and have come up with the following function.
Code:
Public Function PrevInstance() As Boolean
Dim processes(), p As Process
Try
processes = Process.GetProcesses()
For Each p In processes
If Not (p.MainModule Is Nothing) Then
If System.IO.Path.GetFileName(p.MainModule.FileName).ToLower() = "winword.exe" Then
p.Kill()
Exit For
End If
End If
Next p
Catch ex As Exception
Throw
Finally
End Try
End Function
The problem is that it works great if it finds what it's looking for. If "Word" is not running than I get the following error:
Run-time exception thrown: System.ComponentModel.Win32Exception - Unable to enumerate the process modules.
I hope it's just something small that I'm missing.
Thanks for your time.