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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CLOSING Another Program At Certain Time Using VB

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
I have been told that it is possible to automaticaaly close another program at a specific time using VB code. How would I go about doing this? Thanks in advance.
 
' Put the above code in a module
Private Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) _
As Long

Private Declare Function SendMessage _
Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Long) _
As Long


Const NILL = 0&
Const WM_SYSCOMMAND = &H112
Const SC_CLOSE = &HF060&
Const WM_CLOSE = &H10

Dim lngHandle as long
Dim lngHandler as long
'Pass this function the title of the window you
'want to close
Private Sub CloseWindow(sCaption as string)
lngHandle = FindWindow(vbNullString, sCaption)
If lngHandle <> 0 Then
lngHandle1 = SendMessage(lngHandle, WM_SYSCOMMAND, SC_CLOSE, NILL)
End If

End Sub


'You can put the above code in a timer control
'so that periodically it can close any open windows

'Check the website 'It is an excellent resource for all your api needs


Regards,
Rajesh
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top