Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Closing an application

Status
Not open for further replies.

misubud

IS-IT--Management
May 29, 2002
25
NZ
Hi,
need assistance to close an open application
on MS access form load, I call windows media player.
I am able to open the app using a shell, but need assistance to close media player after a set time

open shell as follows:
Call Shell("C:\Program Files\Windows Media Player\mplayer2.exe D:hal sorry.wav", vbMinimizedNoFocus)
--------------

have a pause (timeout) set,
but can't close the above app after pause time!
any assistance appreciated!
 
Hi,

The only way I know of doing this is by using Windows API's.

Create a new Module, paste the following in to it and save the Module as anything you want:

Declare Function EnumWindows Lib "user32.dll" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" (ByVal hWnd As Long) As Long
Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As Long, ByVal Msg As Long, wParam As Any, lParam As Any) As Long

Public Const WM_CLOSE = &H10

Public Function EnumWindowsProc(ByVal hWnd As Long, ByVal lParam As Long) As Long
On Error Resume Next
Dim slength As Long, TitleBar As String
Dim retval As Long
Static winnum As Integer
winnum = winnum + 1
slength = GetWindowTextLength(hWnd) + 1
If slength > 1 Then
TitleBar = Space(slength)
retval = GetWindowText(hWnd, TitleBar, slength)

If Right(TitleBar, 21) = "Windows Media Player" Then
Call SendMessage(hWnd, WM_CLOSE, 0&, 0&)
End If
End If
EnumWindowsProc = 1
End Function

To close Windows Media Player:

Call EnumWindows(AddressOf EnumWindowsProc, 0)

You can close any Application using this Method.

Hope this helps.

Bill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top