[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 186
  • Last Modified:

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!!!

0
anitahelp
Asked:
anitahelp
  • 2
  • 2
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
0
 
anitahelpAuthor Commented:
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
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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.

~IM
0
 
anitahelpAuthor Commented:
Got it!  The vbNullString is where I was having the problems.  Thanks for your time!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now