J. Scott Elblein
Well-known member
G'day all
I am trying to write a very simple program to loop through all instances of a program with the same name, and close them 1) gracefully, and 2) if hanging, Kill it ungracefully.
I have tried two very slightly different versions of code that I found examples of on the net, and both of them appear to do absolutely nothing, even though the code actually does go through proc.closemainwindow code.
Here are the 2 versions I am using so far. Can someone please help shed some light? Thanks!
I am trying to write a very simple program to loop through all instances of a program with the same name, and close them 1) gracefully, and 2) if hanging, Kill it ungracefully.
I have tried two very slightly different versions of code that I found examples of on the net, and both of them appear to do absolutely nothing, even though the code actually does go through proc.closemainwindow code.
Here are the 2 versions I am using so far. Can someone please help shed some light? Thanks!
VB.NET:
For Each proc As Process In Process.GetProcessesByName("PDExplo")
proc.CloseMainWindow()
Next
VB.NET:
Dim processList() As Process
processList = Process.GetProcessesByName("PStart")
For Each proc As Process In processList
If MsgBox("Terminate " & proc.ProcessName & "?", MsgBoxStyle.YesNo, "Terminate?") = MsgBoxResult.Yes Then
proc.CloseMainWindow()
End If
Next
MessageBox.Show("Done")