[RESOLVED] close vb exe fron another vb exe
I have a vb exe on a flash drive that needs price lists and other files updated when plugged into the main pc. To reflect these new prices i need to close and reopen the exe on the flash drive. How ?
I know i can open using shell, but how do i close it?
Re: close vb exe fron another vb exe
I don't know if this will work with an exe on the flash drive but it works on my HD.
Code:
Option Explicit
Private Sub Command1_Click()
Dim strAppTitle As String
'Call with
strAppTitle = "Exact Title bar name of app. Don't include extension."
CloseProgram (strAppTitle)
End Sub
Module Code:
Code:
Option Explicit
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" _
(ByVal hwnd As Long, ByVal lpString As String, ByVal nMaxCount As Long) As Long
Private Declare Function EnumWindows Lib "user32.dll" _
(ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Private Target As String
Private Const WM_CLOSE = &H10
Private Function EnumCallback(ByVal app_hWnd As Long, ByVal param As Long) As Long
Dim buf As String * 256
Dim title As String
Dim length As Long
Dim hWndREC As Long
length = GetWindowText(app_hWnd, buf, Len(buf))
title = Left$(buf, length)
If InStr(1, title, Target, 3) <> 0 Then
PostMessage app_hWnd, WM_CLOSE, 0, 0
End If
EnumCallback = 1
End Function
Public Sub CloseProgram(app_name As String)
Target = app_name
EnumWindows AddressOf EnumCallback, 0
End Sub
Re: close vb exe fron another vb exe
Search the Forums for "Terminate Process" and you will find alot of good code. Then its just Shell or ShellExecute to rerun your app.
Re: close vb exe fron another vb exe
Quote:
Originally Posted by CDRIVE
I don't know if this will work with an exe on the flash drive but it works on my HD.
Code:
Option Explicit
Private Sub Command1_Click()
Dim strAppTitle As String
'Call with
strAppTitle = "Exact Title bar name of app. Don't include extension."
CloseProgram (strAppTitle)
End Sub
Thanks
I should have stated The flash drive forms caption could be a customers name or a lot of things. I do know the name of Flash drive exe and path
Re: close vb exe fron another vb exe
What is this "CloseProgram " function? You forgot to include it :)
Re: close vb exe fron another vb exe
This example shows how to launch an exe and close it,
http://support.microsoft.com/kb/q129797/
Re: close vb exe fron another vb exe
Quote:
Originally Posted by Edgemeal
Thanks that works if the flash exe is opened from the desktop exe as it tracks the process id of the flash exe, but the flash exe is auto run when inserted
Re: close vb exe fron another vb exe
Quote:
Originally Posted by isnoend07
Thanks that works if the flash exe is opened from the desktop exe as it tracks the process id of the flash exe, but the flash exe is auto run when inserted
Right, so I guess you would need to enumerate the running files and find the exe you are interested in. Heres one way to do that I posted here, theres probably better/easier ways to get the same job done tho.
Re: close vb exe fron another vb exe
Quote:
Originally Posted by Edgemeal
Right, so I guess you would need to enumerate the running files and find the exe you are interested in. Heres one way to do that
I posted here, theres probably better/easier ways to get the same job done tho.
Thanks, That works for closing the desktop exe, but it will not allow me to set the path to the flash drive. Both exe have the same name
Re: close vb exe fron another vb exe
Quote:
Originally Posted by RobDog888
What is this "CloseProgram " function? You forgot to include it :)
EEK! I sure did! Sorry about that. I forgot the Module code that includes the API functions:eek2:
I've edited that post and inserted the module.
Re: close vb exe fron another vb exe
i got this to work using GetCurrentProcessId Lib "kernel32" ()
The flash drive exe writes the id to a text file. The main program reads the id
and closes the window. Then reopens using shell
Thanks guys