Consulting

Results 1 to 5 of 5

Thread: Terminating select processes

  1. #1
    VBAX Newbie
    Joined
    Jan 2010
    Posts
    3
    Location

    Terminating select processes

    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

  2. #2
    VBAX Mentor Marcster's Avatar
    Joined
    Jun 2005
    Posts
    434
    Location
    The Win32_Process doesn't have an Application Title property so cannot select a specific instance to terminate based on window title.

  3. #3
    VBAX Newbie
    Joined
    Jan 2010
    Posts
    3
    Location
    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

  4. #4
    VBAX Mentor Marcster's Avatar
    Joined
    Jun 2005
    Posts
    434
    Location
    Hi Clint,

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


    But maybe use something along the lines of:


    [VBA]
    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
    [/VBA]

    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.

  5. #5
    VBAX Newbie
    Joined
    Jan 2010
    Posts
    3
    Location
    Much thanks for your time and input!

    I think this will work for me.

    Thanks again!
    Clint

Posting Permissions

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