FRUSTRATED!!!! My code is supposed to disconnect the DUN connection at a
specified time (which it does without fail), next my code is supposed to
close a program. Any program will do, we can use "Notepad" for this
example. I've tried three different ways to close Notepad, they all work
when tested, however when I place the code at the end or begining of my
close DUN code it NEVER closes the program! I tried creating a Public
Fnction and a Public Sub that closed the program and was called from the
close DUN code but both produced the same results. Someone has to have
seen this before, I've been chasing this bug for several day now and I'm
burnt out on it!

I've tried the TerminateProcess API function as seen here:
http://www.freevbcode.com/ShowCode.Asp?ID=935

Hopefully someone can help out here. I am lost, I'm not getting any erros,
just not working.
********************************Declarations*******************************
Option Explicit

Private Declare Function WaitForSingleObject Lib "kernel32" _
(ByVal hHandle As Long, _
ByVal dwMilliseconds As Long) As Long

Private Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long

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

Private Declare Function IsWindow Lib "user32" _
(ByVal hwnd As Long) As Long

'Constants used by the API functions
Const WM_CLOSE = &H10
Const WM_QUIT = &H12
Const INFINITE = &HFFFFFFFF
********************************CODE*******************************
Public Sub HangUp(HangUpTime As Date)

Dim i As Long
Dim lpRasConn(255) As RasConn
Dim lpcb As Long
Dim lpcConnections As Long
Dim hRasConn As Long
Dim hWindow As Long

Do
If Now() >= HangUpTime Then
Call ActiveConnection
If ActiveConnection = True Then
lpRasConn(0).dwSize = RAS_RASCONNSIZE
lpcb = RAS_MAXENTRYNAME * lpRasConn(0).dwSize
lpcConnections = 0
ReturnCode = RasEnumConnections(lpRasConn(0), lpcb, lpcConnections)
If ReturnCode = ERROR_SUCCESS Then
For i = 0 To lpcConnections - 1
If Trim(ByteToString(lpRasConn(i).szEntryName))= Trim(gstrISPName) Then
hRasConn = lpRasConn(i).hRasConn
ReturnCode = RasHangUp(ByVal hRasConn)
End If
Next i
End If
hWindow = FindWindow(vbNullString, "Notepad")
If hWindow <> 0& Then 'found it
PostMessage hWindow, WM_CLOSE, 0&, ByVal 0&
End If
Unload Me
Exit Sub
Else
hWindow = FindWindow(vbNullString, "Notepad")
If hWindow <> 0& Then 'found it
PostMessage hWindow, WM_Close, 0&, ByVal 0&
End If
Unload Me
Exit Sub
End If
Else
For i = 1 To 30
Sleep (1000)
DoEvents
Next i
End If
Loop
End Sub
************************************************************************

Sorry for the long post

TIA