close divx player using a button on a form

Posted on 2006-03-20
Last Modified: 2010-05-01
Hi I was wondering if you could help me I've got a form with a button on it that opens the Divxplayer via the shell command, but once the divx finishes playing it just stops on the screen. I would like to shut down the divx player using another button on the form.How would I do this and removing all traces from the cpu memoery?
Question by:Garstuard
    LVL 85

    Accepted Solution

    Option Explicit

    Private Const PROCESS_ALL_ACCESS = &H1F0FFF
    Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
    Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
    Private Declare Sub TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long)

    Private taskID As Double

    Private Sub Form_Load()
        Command2.Enabled = False
    End Sub

    Private Sub Command1_Click()
        If taskID <> 0 Then
            KillShell taskID
        End If
        taskID = Shell("notepad.exe", vbNormalFocus)
        Command2.Enabled = True
    End Sub

    Private Sub Command2_Click()
        If taskID <> 0 Then
            KillShell taskID
            taskID = 0
        End If
        Command2.Enabled = False
    End Sub

    Private Sub KillShell(ByVal taskID As Double)
        On Error Resume Next

        Dim hProcess As Long
        Dim lExitCode As Long
        Dim lRet As Long

        If taskID <> 0 Then
            hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0&, taskID)
            If hProcess <> 0 Then
                GetExitCodeProcess hProcess, lExitCode
                If lExitCode <> 0 Then
                    TerminateProcess hProcess, lExitCode
                End If
            End If
        End If
    End Sub

    Author Comment

    Big apologies for not responding to the kind solution provided. It was a mad time for what we were developing at the time...working 24hrs a day. Thanks for taking the time to post, I have to admit we found a different work around for that solution but i'm sure the one listed works.
    LVL 49

    Expert Comment

    If you have a few minutes to briefly describe the alternate technique, doing so could help improve the EE Solutions database.  Thanks!
    -- DanRollins EE Page Editor

    Author Comment

    Sorry, I should have been more specific, due to time management at the time and changing our development strategy, the work-around we used was by using a developer to embed a vlc player into flash program. Subsequently [and i'm afraid i'm not party to his code] each .divx files now auto-closes upon completion.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Introduction This article makes the case for using two modules in your VBA/VB6 applications to provide both case-sensitive and case-insensitive text comparison operations.  Recently, I solved an EE question using the LIKE function.  In order for th…
    Article by: Martin
    Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now