• Help with killing process please

    From scbs29@21:1/5 to All on Wed Dec 11 16:36:25 2024
    I have written a program which reads a list of videos on my system and calls MediaInfo for each film to get Width and Height.
    I cannot, however, kill the MediaInfo process after each video so Task Manager shows
    an increasing list of MediaInfo processes and eventually locks up my pc.
    What I have tried so far from looking on the Internet are:

    Line Input #intIn, strFilm
    sCom = "C:\m\MediaInfo.exe --Output=General--%CompleteName%\nVideo;--%Width%,--%Height% --logfile=infox.txt"
    sCom = sCom & " " & """" & strFilm & """"

    Call Shell(sCom, vbMinimizedFocus)

    DoEvents
    Shell "taskkill.exe /f /t /im MediaInfo.exe", vbMinimizedFocus

    DoEvents
    Open "infox.txt" For Input As #intTemp

    '---------------------------------------------------------------------------

    If IsProcessRunning("MediaInfo.exe") = True Then
    TerminateProcess ("MediaInfo.exe")
    End If

    '-----------------------------------------------------------------------------

    Kill_Program
    Sub Kill_Program()
    Dim WinWnd As Long

    WinWnd = FindWindow(vbNullString, "c:\m\mediainfo.exe")

    If WinWnd <> 0 Then
    PostMessage WinWnd, WM_CLOSE, 0&, 0&
    Else
    ' do nothing or
    MsgBox "No window of that name exists."
    End If
    End Sub

    '---------------------------------------------------------------------------------------

    Shell "taskkill.exe /f /t /im C:\m\MediaInfo.exe"

    '-------------------------------------------------------------------------------------
    KillProg
    Sub KillProg()
    Dim target_hwnd As Long
    Dim target_process_id As Long
    Dim target_process_handle As Long
    Dim strTarget As String
    strTarget = "mediainfo.exe"
    ' Get the target's window handle.
    target_hwnd = FindWindow(vbNullString, strTarget) 'txtTargetTitle.Text)
    If target_hwnd = 0 Then
    MsgBox "Error finding target window handle"
    Exit Sub
    End If

    ' Get the process ID.
    GetWindowThreadProcessId target_hwnd, target_process_id
    If target_process_id = 0 Then
    MsgBox "Error finding target process ID"
    Exit Sub
    End If

    ' Open the process.
    target_process_handle = OpenProcess( _
    SYNCHRONIZE Or PROCESS_TERMINATE, _
    ByVal 0&, target_process_id)
    If target_process_handle = 0 Then
    MsgBox "Error finding target process handle"
    Exit Sub
    End If

    ' Terminate the process.
    If TerminateProcess(target_process_handle, 0&) = 0 Then
    MsgBox "Error terminating process"
    Else
    MsgBox "Process terminated"
    End If

    ' Close the process.
    CloseHandle target_process_handle
    End Sub

    '-------------------------------------------------------------------------------

    TerminateProcess ("mediainfo.exe")
    Dim blnRet As Boolean
    blnRet = TerminateEXE("c:\m\mediainfo.exe")

    Can anyone please help ?
    TIA

    --
    remove fred before emailing
    --
    remove fred before emailing

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)