[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 189
  • Last Modified:

close divx player using a button on a form

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?
0
Garstuard
Asked:
Garstuard
  • 2
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
0
 
GarstuardAuthor Commented:
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.
0
 
DanRollinsCommented:
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
0
 
GarstuardAuthor Commented:
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.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now