Results 1 to 8 of 8

Thread: Killing my App

  1. #1

    Thread Starter
    Fanatic Member Gaffer's Avatar
    Join Date
    Nov 2000
    Location
    London
    Posts
    828

    Question Killing my App

    Here's the rub:

    We have a legacy process that involves a DOS bat file opening an Access97 mdb file with command line parameters.

    The Access97 database has an autoexec macro (for those not familiar with Access, it's a macro envoked on startup) which does its jobs and then closes Access down using DoCmd.Quit

    The problem is that after it closes the mdb file down, an instance of Access remains open. This instance can only be closed using task manager. I need to close the Application.

    The solution I am about to suggest to these guys is to use TerminateProcess API call to close this instance.
    But where should I use it? A separate tiny VB6 exe? In the Access VBA code itself? Is there an easier solution?


  2. #2
    Hyperactive Member anita2002's Avatar
    Join Date
    Dec 2001
    Location
    In u'r Heart
    Posts
    482
    Can't imagine life without VB
    (Various Boyfriends)

  3. #3

    Thread Starter
    Fanatic Member Gaffer's Avatar
    Join Date
    Nov 2000
    Location
    London
    Posts
    828
    Thanks Anita, but I don't really want to delete the exe, because in this case it is msaccess.exe. It is msaccess.exe that needs to be shut down. The only way to do it manually is by using End Process on the Task List.

    Thanks anyway

  4. #4
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    try this http://www.4guysfromrolla.com/webtec...1.update.shtml

    and if that does not work here is some code that might help you..

    VB Code:
    1. Private Type PROCESSENTRY32
    2.     dwSize As Long
    3.     cntUsage As Long
    4.     th32ProcessID As Long
    5.     th32DefaultHeapID As Long
    6.     th32ModuleID As Long
    7.     cntThreads As Long
    8.     th32ParentProcessID As Long
    9.     pcPriClassBase As Long
    10.     dwFlags As Long
    11.     szexeFile As String * 6400
    12. End Type
    13. Private Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, lProcessID As Long) As Long
    14. Private Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
    15. Private Declare Function OpenProcess Lib "Kernel32.dll" _
    16.   (ByVal dwDesiredAccessas As Long, ByVal bInheritHandle As Long, _
    17.       ByVal dwProcId As Long) As Long
    18. Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
    19. Private Declare Function CloseHandle Lib "Kernel32.dll" _
    20.    (ByVal Handle As Long) As Long
    21. Private Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
    22.  
    23. Public Function KillProcessByName(ExeName As String) As Boolean
    24.     Const PROCESS_ALL_ACCESS = 0
    25.     Dim uProcess As PROCESSENTRY32
    26.     Dim rProcessFound As Long
    27.     Dim hSnapshot As Long
    28.     Dim szExename As String
    29.     Dim exitCode As Long
    30.     Dim myProcess As Long
    31.     Dim AppKill As Boolean
    32.     Dim appCount As Integer
    33.     Dim i As Integer
    34.     On Local Error GoTo Finish
    35.     appCount = 0
    36.    
    37.     Const TH32CS_SNAPPROCESS As Long = 2&
    38.    
    39.     uProcess.dwSize = Len(uProcess)
    40.     hSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
    41.     rProcessFound = ProcessFirst(hSnapshot, uProcess)
    42.    
    43.     Do While rProcessFound
    44.         i = InStr(1, uProcess.szexeFile, Chr(0))
    45.         szExename = LCase$(Left$(uProcess.szexeFile, i - 1))
    46.         If Right$(szExename, Len(ExeName)) = LCase$(ExeName) Then
    47.             KillProcessByName = True
    48.             appCount = appCount + 1
    49.             myProcess = OpenProcess(PROCESS_ALL_ACCESS, False, uProcess.th32ProcessID)
    50.             AppKill = TerminateProcess(myProcess, exitCode)
    51.             Call CloseHandle(myProcess)
    52.         End If
    53.         rProcessFound = ProcessNext(hSnapshot, uProcess)
    54.     Loop
    55.  
    56.     Call CloseHandle(hSnapshot)
    57. Finish:
    58. End Function

  5. #5

    Thread Starter
    Fanatic Member Gaffer's Avatar
    Join Date
    Nov 2000
    Location
    London
    Posts
    828
    Purrrrrfect It looks exactly what I need - I'll test this afternoon

    Thank

  6. #6
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    Originally posted by Gaffer
    Purrrrrfect It looks exactly what I need - I'll test this afternoon

    Thank
    no problem.. i use it now in a few apps so it should work for ya no problem!

  7. #7
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    DoCmd.Quit should close MS Access.
    If MS Access does not close, it is probably due to poor programming in the Access application.
    I know that this can occur if recordsets are not closed, but run out of scope instead.

    You can either kill the MS Access process (but be sure the app has finished!), or fix the Access application.

  8. #8
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    I is exaclty due to poor programming techniques. All the recordset that were opened were not close properly. The biggest problem in this area is a recordset variable that was used multiple times without being closed or only closed once.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width