|
-
Dec 13th, 2002, 04:39 AM
#1
Thread Starter
Fanatic Member
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?
-
Dec 13th, 2002, 06:02 AM
#2
Hyperactive Member
Can't imagine life without VB
(Various Boyfriends)
-
Dec 13th, 2002, 06:35 AM
#3
Thread Starter
Fanatic Member
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
-
Dec 13th, 2002, 08:47 AM
#4
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:
Private Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
dwFlags As Long
szexeFile As String * 6400
End Type
Private Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, lProcessID As Long) As Long
Private Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function OpenProcess Lib "Kernel32.dll" _
(ByVal dwDesiredAccessas As Long, ByVal bInheritHandle As Long, _
ByVal dwProcId As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function CloseHandle Lib "Kernel32.dll" _
(ByVal Handle As Long) As Long
Private Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Public Function KillProcessByName(ExeName As String) As Boolean
Const PROCESS_ALL_ACCESS = 0
Dim uProcess As PROCESSENTRY32
Dim rProcessFound As Long
Dim hSnapshot As Long
Dim szExename As String
Dim exitCode As Long
Dim myProcess As Long
Dim AppKill As Boolean
Dim appCount As Integer
Dim i As Integer
On Local Error GoTo Finish
appCount = 0
Const TH32CS_SNAPPROCESS As Long = 2&
uProcess.dwSize = Len(uProcess)
hSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
rProcessFound = ProcessFirst(hSnapshot, uProcess)
Do While rProcessFound
i = InStr(1, uProcess.szexeFile, Chr(0))
szExename = LCase$(Left$(uProcess.szexeFile, i - 1))
If Right$(szExename, Len(ExeName)) = LCase$(ExeName) Then
KillProcessByName = True
appCount = appCount + 1
myProcess = OpenProcess(PROCESS_ALL_ACCESS, False, uProcess.th32ProcessID)
AppKill = TerminateProcess(myProcess, exitCode)
Call CloseHandle(myProcess)
End If
rProcessFound = ProcessNext(hSnapshot, uProcess)
Loop
Call CloseHandle(hSnapshot)
Finish:
End Function
-
Dec 13th, 2002, 08:52 AM
#5
Thread Starter
Fanatic Member
Purrrrrfect It looks exactly what I need - I'll test this afternoon
Thank
-
Dec 13th, 2002, 08:54 AM
#6
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!
-
Dec 13th, 2002, 10:18 AM
#7
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.
-
Dec 13th, 2002, 02:33 PM
#8
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|