|
-
Aug 19th, 2008, 12:01 PM
#1
Thread Starter
PowerPoster
[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?
Last edited by isnoend07; Aug 19th, 2008 at 12:04 PM.
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders 
-
Aug 19th, 2008, 12:47 PM
#2
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
Last edited by CDRIVE; Aug 19th, 2008 at 06:08 PM.
Reason: Missing Module code
<--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
If topic has been resolved, please pull down the Thread Tools & mark it Resolved.
Is VB consuming your life, and is that a bad thing?? 
-
Aug 19th, 2008, 12:47 PM
#3
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.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 19th, 2008, 12:59 PM
#4
Thread Starter
PowerPoster
Re: close vb exe fron another vb exe
 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
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders 
-
Aug 19th, 2008, 01:58 PM
#5
Re: close vb exe fron another vb exe
What is this "CloseProgram " function? You forgot to include it
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 19th, 2008, 02:22 PM
#6
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/
-
Aug 19th, 2008, 02:35 PM
#7
Thread Starter
PowerPoster
Re: close vb exe fron another vb exe
 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
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders 
-
Aug 19th, 2008, 02:49 PM
#8
Re: close vb exe fron another vb exe
 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.
-
Aug 19th, 2008, 03:36 PM
#9
Thread Starter
PowerPoster
Re: close vb exe fron another vb exe
 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
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders 
-
Aug 19th, 2008, 05:52 PM
#10
-
Aug 19th, 2008, 08:03 PM
#11
Thread Starter
PowerPoster
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
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|