How to kill process?

  • Thread starter Thread starter Brett
  • Start date Start date
B

Brett

How do I gracefully kill a process than restart it? The process Image Name
is known.

Thanks,
Brett
 
Hello Brett,

hopes this helps

Regards

Dim myProcesses() As Process
Dim myProcess As Process
Dim teller As Integer = 0
'' Returns array containing all instances of "Notepad".
myProcesses = Process.GetProcessesByName("Notepad")
For Each myProcess In myProcesses
myProcess.CloseMainWindow()
teller += 1
Next
If teller > 0 Then
MessageBox.Show("closed")
Else
MessageBox.Show("Nothing to be closed")
End If

' start notepad
myProcess.Start("notepad.exe")
 
Do you know the name of the app, or any word that will appear in the title
bar? If so, you can loop through processes until you find the one that
matches the info you know about the title bar.

Dim knowntext as String = "whatever I know in title bar"
Dim proc as Process
Dim processlist() as Process
processlist = Process.GetProcesses
For each proc in processlist
If InStr(proc.ProcessName.ToUpper, knowntext.ToUpper)
If Not proc.CloseMainWindow() Then proc.Kill()
End If

(the double attempt to shut it down is deliberate--the first time to be nice
about it, the second to just get rid of it)

Terp
 
This works good for Notepad. The problem is the program has no interface.
It's call FreePops, http://www.freepops.org/en/. I can start a new instance
of it but the code won't close it. It sits in the tray and I can only right
click it to get a menu with About and Exit. There isn't any title bar. I
see this in the taskmanager, "freepopsd.exe".

How do I close that?

Thanks,
Brett
 
Actually, I have to use myProcess.Kill() rather than close() or
closemainwindow() before it shuts the app down. This is what I wanted to
avoid.

Any suggestions?

Thanks,
Brett
 
BTW, I can right click on the program in the tray and select Exit to close
it.

Brett
 

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

Back
Top