PDA

View Full Version : Terminating select processes



cherman
01-06-2010, 10:19 AM
I have implemented the code found in the article listed below and it works well, but what I want to do, if possible, is to bypass terminating a certain instance of msaccess.exe based on the Application Title or some other static value.

I don't think I can use the PID for this, as it seems to be dynamically assigned each time Access is open (or for any app for that matter). I always want to bypass the instance of Access that is running this code because it always gets terminated by the code.

vbaexpress.com/kb/getarticle.php?kb_id=811

Thanks!
Clint

Marcster
01-06-2010, 10:56 AM
The Win32_Process doesn't have an Application Title property so cannot select a specific instance to terminate based on window title.

cherman
01-06-2010, 12:01 PM
Thanks for your reply!

Do you know if there is some value associated with Win32_Process that I might be able to use?

Thanks again,
Clint

Marcster
01-06-2010, 01:00 PM
Hi Clint,

There doesn't seem to be :-(. http://msdn.microsoft.com/en-us/library/aa394372%28VS.85%29.aspx


But maybe use something along the lines of:



Option Explicit

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 Any) As Long

Private Const WM_CLOSE = &H10
Sub TerminateProgamByWindowTitle()
Dim strWindowName As String
Dim lngWindow As Long

strWindowName = InputBox("Type the Application Text of the program you want close.", "Close program?")

lngWindow = FindWindow(vbNullString, strWindowName)

SendMessage lngWindow, WM_CLOSE, 0, vbNullString
End Sub


This code finds the window that has the given window title text and
sends the close command to it.


I have NOT fully tested this though. Please use with caution.

cherman
01-06-2010, 07:07 PM
Much thanks for your time and input!

I think this will work for me.

Thanks again!
Clint