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!!!
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!!!
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Got it! The vbNullString is where I was having the problems. Thanks for your time!
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