110 Points Kill Running Application

Need working example of killing an application that is running from another application. I saw a nice small little example of this somewhere, didn't keep it for inspection and here i am !
Using visual 5.0 can't afford 6.0
Thanks
stnic
stnicAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hatem72Commented:
'This VB program can kill any applications running on windows

'put it in the module.bas
Option Explicit
DefInt A-Z

Declare Function Findwindow Lib "User" (ByVal Class&, ByVal Caption&)
Declare Function GetWindow Lib "User" (ByVal hWnd, ByVal wCmd)
Declare Function GetNextWindow Lib "User" (ByVal hWnd, ByVal wCmd)
Declare Function GetWindowText Lib "User" (ByVal hWnd, ByVal Buf$, ByVal lBuf)
Declare Sub ShowWindow Lib "User" (ByVal hWnd, ByVal nCmd)
Declare Function SendMessage Lib "User" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Any) As Long

Const WM_CLOSE = &H10
Const GW_HWNDFIRST = 0
Const GW_HWNDNEXT = 2

Function GetWinCaption$(hWnd)

    Dim strCaption As String * 256
    Dim NumChars

    NumChars = GetWindowText(hWnd, strCaption, 256)
    GetWinCaption$ = Left$(strCaption, NumChars)

End Function

'
' This program checks all the application windows' captions, if there is
' a match, it will ask the user to teminate the program or not.
' If there is nothing matches, it will terminate itself.
'
' This is useful when the user running an application and try to install
' it while it is running.
'
' Copyright 1997 (c) 2Link Consulting Inc.
' By Raymond Tsang
'
Sub Main()

    Dim Wnd, lResult As Long, iResult
             
    Wnd = SearchWindow("Your application name")
    If Wnd <> 0 Then
        iResult = MsgBox("Another copy of *** is running, do you want to terminate it before starting the installation?", 4, "KillApp")
        If iResult = 6 Then
            lResult = SendMessage(Wnd, WM_CLOSE, 0, 0&)
        End If
   
        End
    End If

End Sub

Function SearchWindow(ByVal strSearch$)

    Dim hWnd

    ' Find the first window's handle
    hWnd = Findwindow(0, 0)
    hWnd = GetWindow(hWnd, GW_HWNDFIRST)
   
    ' Set all comparison to upper case
    strSearch$ = UCase$(strSearch$)
   
    ' Start the loop for all windows
    Do While hWnd <> 0
       
        ' If the searching caption is a sub string of the current window's caption
        If InStr(UCase$(GetWinCaption(hWnd)), strSearch$) Then
            ' Return the window's handle
            SearchWindow = hWnd
            Exit Function
        End If
        ' Get the next window handle
        hWnd = GetNextWindow(hWnd, GW_HWNDNEXT)
    Loop

End Function



0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
stnicAuthor Commented:
Hey, thanks a lot. Works for me :)
stnic
0
swelenskCommented:
Hi -
This is exactly what I'm looking for...
I'm creating installs using Wise InstallMaster, which will let me make dll function calls...however, I've been unsuccessful at killing the application with a user32.dll call -- so considering running a small VB exe to do it.
One issue - If I create a module using the VB posted by hatem72, i get a debug error on "hWnd = Findwindow(0, 0)" regarding "user".
Looks like there's something obvious I need to define, but not sure what it is.
Can you help?
Thanks
--
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.