Closing an application

Posted on 2004-11-16
Last Modified: 2010-04-23
I am sure this has been hashed and rehashed but I have to ask.  Is there a way to close an application in  I used the "FindWindow" in VB6 but I can't seem to figure out the equivilent.  This is basically going to be used to kill a VB application, delete the executable, copy over a new application with the same name and run it (sort of an upgrade type process).  Any help is greatly appreciated!!!

Question by:anitahelp
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    The VB6 declaration is:

        Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

    The VB.Net declaration would be:

        Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer

    In general, you simply change all occurrences of Long to Integer for API declarations.


    Author Comment

    Ok, then something like this?

            Dim sTitle As String
            Dim iHwnd As Integer
            Dim iReturn As Object

            sTitle = "MyApplication"
            iHwnd = FindWindow(0, sTitle)
            If iHwnd <> 0 Then
                iReturn = PostMessage(iHwnd, WM_QUIT, 0, 0)
            End If
    LVL 85

    Accepted Solution

    I think you need to use vbNullString instead of 0 in your FindWindow() call but I'm not sure about that.

    Make sure you have WM_QUIT declared.


    Author Comment

    Got it!  The vbNullString is where I was having the problems.  Thanks for your time!

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
    Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now