No announcement yet.

Kill Background Process

  • Filter
  • Time
  • Show
Clear All
new posts

  • Kill Background Process

    On a side note, the Windows Voice Dictation app is known to freeze on occasion.

    It runs as a background process called "Microsoft Text Input Application", which I can kill using Task Manager but would rather do it programmatically.

    Using CMD with TaskList, I can see there are two EXE's which seem to be involved - speech.exe and textinputhost.exe.

    Are there any caveats with using TaskKill to close the apps from with my PowerBASIC app (shelling to CMD to get acces to it).

  • #2
    It is better to use Terminate process than Taskkill as the latter is unreliable

    The following function listed there will do the job cleanly :

    FUNCTION TerminateProc


    • #3
      Doing Ctl F on linked page for "Taskkill" yields zero hits.

      So, while Taskkill may be unreliable, you've offered nothing to support that conclusion.

      Also, no mention of a problem at MSDN:
      taskkill | Microsoft Docs

      Again, you are offering advice without even reading the source you mentioned, or the authorative source.



      • #4
        Are there any caveats with using TaskKill to close the apps from with my PowerBASIC app (shelling to CMD to get acces to it).
        If you are worried about all the typing involved, it only takes three lines of source code to use TerminateProcess()*..
        * Now, to use EITHER TerminateProcess() or SHELL() **CORRECTLY** you need to add the error handling code... which makes the actual "do it" code in either case virtually moot.

        And the error-handling is a heck of lot easier when using TerminateProcess()... because it RETURNS a success/fail code!
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]


        • #5
          Howdy, MCM!

          No, I was wondering if there are any OS level concerns about using TaskKill. I haven't read of any, but TaskKill seems to have enough power to be cautious with it.

          It could be worrisome like code that deletes a folder - you want to be sure you don't accidentally delete c:\windows!

          In post #38 of the link Anne mentions, Pierre gives a quite useful function that shuts down a specified EXE. Anne's comment aside, I don't know if his function is any more or less reliable than TaskKill.

          The information I've read suggests that some apps are resistance to TaskKill but if it works once on the app, it will always work. I've not seen that mentioned in any MSDN articles.


          • #6
            When Windows Voice Recognition freezes, have you tried saying "start listening" ?
            "Not my circus, not my monkeys."


            • #7
              Howdy, Eric!

              Yep. I've also clicked on the microphone in the Voice Dictation bar. When the bar is frozen, neither action works to get Voice Dictation working again.

              There is also a roughly 8s timeout after which the bar will go inactive. In that case, "Start Listening" does not work. I'm assuming Start Listening is supported by the Speech Recognition, not the Voice Dictation app.

              I've seen posts elsewhere on the web from folks who have seen the same problem.

              I have also seen the Voice Dictation bar tell me that the service is not available and that I need to try later - server issue of some kind, I suppose. But that is different than the freeze that I have occasionally seen.


              • #8
                Are you using FireFox?
                "Not my circus, not my monkeys."


                • #9
                  Howdy, Eric!

                  No - there's no browser involved. This has to do with using Voice Dictation in a PowerBASIC app, such as this in-work demo:

                  #Compile Exe
                  #Dim All
                  %Unicode = 1
                  #Include ""
                  #Include ""
                  Declare Function RtlAdjustPrivilege Lib "NtDll.dll" Alias "RtlAdjustPrivilege" _
                  (ByVal PrivilegeIndex As Dword, ByVal EnableIfTrueElseDisable As Long, _
                   ByVal ThreadIfTrueElseProcess As Dword, ByRef WasAlreadyEnableIfTrue As Long) As Long
                  Enum Equates Singular
                     IDC_Speech = 500
                  End Enum
                  Global hDlg As Dword, SpeechON As Long
                  Function PBMain() As Long
                     Dialog Default Font "Arial Black", 14, 0
                     Dialog New Pixels, 0, "gbSpeech",300,300,500,350, %WS_OverlappedWindow To hDlg
                     Control Add Button, hDlg, %IDC_Speech,"Speech", 10,10,100,25
                     Control Add Button, hDlg, %IDC_Clear,"Clear", 120,10,65,25
                     Control Add Button, hDlg, %IDC_Hide,"ReSize", 10,50,100,25
                     Control Add Button, hDlg, %IDC_Kill,"Kill", 120,50,100,25
                     Control Add TextBox, hDlg, %IDC_TextBox, "", 10, 90, 230, 150, %ES_MultiLine Or %ES_WantReturn
                     Dialog Show Modal hDlg Call DlgProc
                  End Function
                  CallBack Function DlgProc() As Long
                     Local w,h As Long
                     Select Case Cb.Msg
                        Case %WM_Command
                           Select Case Cb.Ctl
                              Case %IDC_Speech
                                 TerminateProc "speechruntime.exe"
                                 TerminateProc "textinputhost.exe"
                  Sleep 500
                                 SpeechON Xor=1
                                 Control Set Focus hDlg, %IDC_TextBox
                                 If SpeechON Then ToggleSpeech
                              Case %IDC_Clear
                                 Control Set Text hDlg, %IDC_TextBox, ""
                                 Control Set Focus hDlg, %IDC_TextBox
                              Case %IdCancel : Dialog End hDlg
                              Case %IDC_Hide : HideBar
                              Case %IDC_Kill
                                 TerminateProc "speechruntime.exe"
                                 TerminateProc "textinputhost.exe"
                           End Select
                        Case %WM_Size
                           Dialog Get Client hDlg To w,h
                           Control Set Size hDlg, %IDC_TextBox, w-20, h-100
                        Case %WM_Destroy
                           If SpeechON Then ToggleSpeech
                     End Select
                  End Function
                  Sub ToggleSpeech
                     keybd_event(%VK_LWIN, &H45, 0, 0)
                     keybd_event(%VK_H, &H45, 0, 0)
                     keybd_event(%VK_H, &H45, %KEYEVENTF_KEYUP, 0)
                     keybd_event(%VK_LWIN, &H45, %KEYEVENTF_KEYUP, 0)
                  End Sub
                  Function TerminateProc(zFileName As WStringZ) As Long         'Pierre
                   Local ProcEntry As PROCESSENTRY32
                   Local hSnapshot As Dword
                   Local hProc     As Dword
                   hSnapshot        = CreateToolhelp32Snapshot(%TH32CS_SNAPPROCESS, %NULL)
                   ProcEntry.dwSize = SizeOf(PROCESSENTRY32)
                   If Process32First(hSnapshot, ProcEntry) Then
                       If LCase$(ProcEntry.szExefile) = LCase$(zFileName) Then
                         hProc = OpenProcess(%PROCESS_TERMINATE, %FALSE, ProcEntry.th32ProcessID)
                         If hProc Then
                             If TerminateProcess(hProc, ByVal %NULL) Then
                               Function = %TRUE 'Success
                               CloseHandle(hProc) 'Not terminated, do clean up
                             End If
                         End If
                         Exit Do
                       End If
                     Loop While Process32Next(hSnapshot, ProcEntry)
                   End If
                  End Function
                  Sub HideBar
                     Local w,h As Long, pt As Point, hWin As Dword
                     Desktop Get Client To w,h
                     pt.x = w/2 : pt.y = 10
                     hWin = WindowFromPoint(pt)
                     SetWindowPos GetParent(hWin), %HWND_NoTopMost, 0,0,200,200 ,%SWP_NoMove
                  End Sub


                  • #10
                    FireFox and voice recognition don't play well together, so just using FF on the same PC can cause problems, and I thought I remembered that you use it.
                    "Not my circus, not my monkeys."


                    • #11
                      Howdy, Eric!

                      Yes, I do have it installed but have not used in quite some time.


                      • #12
                        FWIW, I use FF and have not experienced what Gary is experiencing. I assume that Voice Dictation has a similar set of 'what to say' for different conditions like Speech Recognition does, but there could be slight differences in the syntax. For example, "Start Listening" from Speech Recognition might be "Begin Listening" in Voice Dictation. I'm shying away from testing the Voice Dictation because I haven't had many issues with Speech Recognition and I don't want to start any.
                        Gary are you sure that the Speech Recognition is completely shut down while using Voice Dictation? I did find at one time that the Speech Recognition would become active willy-nilly, but that was in the early days of using it and I don't remember just what steps I took to make it quit.
                        In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.