Link to home
Start Free TrialLog in
Avatar of anitahelp
anitahelp

asked on

Closing an application

Hello,
I am sure this has been hashed and rehashed but I have to ask.  Is there a way to close an application in vb.net?  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!!!

Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

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.

~IM
Avatar of anitahelp
anitahelp

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Got it!  The vbNullString is where I was having the problems.  Thanks for your time!