Announcement

Collapse
No announcement yet.

How do I kill an application?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How do I kill an application?

    I'm having a mental block. I know there must be a way to do this, but I can't remember how.

    On my brother's HS setup, the TTS periodicallly just stops. I've checked everything, and the only thing I can do is to kill and restart the speaker. In the absence of knowing what the real problem is, I want to set up an event with a script to automatically kill and restart the speaker, like a couple of times a day.

    Can anyone help me with a VB.NET command to kill an application?

    Steve

    #2
    Whilst I know you asked for .net (and I know its out there somewhere for this), this is a VBS file that works and might give you an idea...

    Sub Main
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process Where Name = 'Winamp3.exe'")
    For Each objProcess in colProcessList
    objProcess.Terminate()
    Next
    End Sub
    Replace 'Winamp3.exe' of course with Speaker.exe

    And yes I have problems with TTS also, I think mine is a connection issue - what I have found so far is only launch the speaker client after HS is fully loaded. If it is left unconnected in the tray and I then started HS the speaker client would connect to HS and the tray icon turns white, but the client does not respond to any commands given to it.

    Comment


      #3
      Do not know and could be wrong, but PSShutdown comes to mind.
      sigpic
      A founder member of "The HA Pioneer Group" otherwise known as the "Old farts club!"

      Comment


        #4
        Originally posted by mrhappy View Post
        Whilst I know you asked for .net (and I know its out there somewhere for this), this is a VBS file that works and might give you an idea...
        Mrhappy:

        Work perfectly! Thank you very much! I just put it into a VBScript file for HS and it seems to work fine.

        How in the world did you find that piece of code?!

        Steve

        Comment


          #5
          Just FYI, I did figure out another way (although I'm using MrHappy's solution on my brother's machine for now). Here's the second (VB.NET) version that seems to work as well:
          Code:
          Imports System.Diagnostics
           
          Sub Main(ByVal dummy as Object)
              Dim ProcessList() as Process
              ProcessList = Process.GetProcessesByName("Speaker")
              For Each proc as Process In ProcessList
                  proc.kill()
              Next
              hs.WaitSecs(8)
              hs.Launch("Speaker.exe")
          End Sub
          Steve

          Comment


            #6
            Originally posted by stevea View Post
            Mrhappy:

            Work perfectly! Thank you very much! I just put it into a VBScript file for HS and it seems to work fine.

            How in the world did you find that piece of code?!

            Steve
            Its on this very forum somewhere, cannot remember what I searched for but its worked fine for my needs so did'nt see the point of finding a .net alternative for something relatively simple. As above I use it to kill winamp when I have launched it from HS.

            And of course you could probably enhance it by passing the application name as a parameter instead of coding it into the script.

            Comment


              #7
              Steve,

              I know you are more than capable of writing your own stuff but for others who are scripting challenged, I did write this for situations such as yours.
              Jon

              Comment


                #8
                Originally posted by jon00 View Post
                Steve,

                I know you are more than capable of writing your own stuff but for others who are scripting challenged, I did write this for situations such as yours.
                Jon,

                As it turns out, I do have the App/Process control package (I think I even donated some to you for it), although I have never used it. In looking at the docs though, it looks like I can kill and restart something if it shows up in the Application list of the Task Manager. The Speaker app doesn't show up there while it is in the tray. If I double click on it the window opens and it shows up. Based on that, I would have assumed (if I would have thought to look!) that it wouldn't work in this case. Am I wrong?

                Steve

                P.S. A Jon00 solution should have been my FIRST place to look. Silly me!

                Comment


                  #9
                  It will work with any process showing in task manager.
                  Jon

                  Comment


                    #10
                    Jon,

                    My bad. I had mis-read the doc file. There was some explicit wording that what could be controlled could not include the file extension, but everything in the process listing on the task manager does, so I figured it must be the names from the applications tab.

                    I've already got the script installed and running for my brother (and I don't think I downloaded your package for him), but I'll keep this in mind. Like you said, your app is perfect for those that don't code.

                    Steve

                    Comment

                    Working...
                    X