We help IT Professionals succeed at work.

How to not only stop and start a service but kill

howtodrivesafe
howtodrivesafe used Ask the Experts™
on
I know how to start stop services programatically. However I have this stubborn service that's a 3rd party vendor tool. I use that's hanging all my stuff up but going into a forever stopping mode. How can I kill a service as I would an application programmatically.

I have this sample code but can't get it to kill the actual service.

 Try
                                                ' if exception is caught will attempt to force process removal
                                                'willl attempt to kill process if sends a catch statement else this satement will be bypassed
                                                For Each pr As Process In Process.GetProcesses
                                                    If (pr.ProcessName = "SpeechServer") Then
                                                        pr.CloseMainWindow()
                                                        pr.WaitForExit(15000)
                                                        If Not pr.HasExited Then
                                                            pr.Kill()
                                                        End If
                                                        Exit For
                                                    End If
                                                Next

                                            Catch ex As Exception
                                                MsgBox(ex.Message + " problem with kill section Character Server Stopping ")
                                            End Try
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Dirk HaestProject manager

Commented:
Do you get an error when you try to kill the app or is it just staying in the modus "stopping" ?
Do you see anything from errormessage in the eventviewer of windows ?
I figured it out.


                                            Try



                                                ' if exception is caught will attempt to force process removal
                                                'willl attempt to kill process if sends a catch statement else this satement will be bypassed
                                                Dim name1 As String = "SpeechServer"

                                                For Each process1 As Process In Process.GetProcesses()
                                                    If process1.ProcessName.Equals(name1) Then
                                                        lblStatusUpdate.Text = "Speech Server has halted killing process"
                                                        lblStatusUpdate.Refresh()
                                                        process1.Kill()
                                                        Return
                                                    End If
                                                Next

                                            Catch ex As Exception
                                                MsgBox(ex.Message + " problem with kill section Character Server Stopping ")
                                            End Try

Author

Commented:
I figured out solution beore response.