Results 1 to 11 of 11

Thread: [RESOLVED] close vb exe fron another vb exe

  1. #1

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Resolved [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

  2. #2
    PowerPoster CDRIVE's Avatar
    Join Date
    Jul 2007
    Posts
    2,620

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

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  4. #4

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    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
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  6. #6
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    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/

  7. #7

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: close vb exe fron another vb exe

    Quote Originally Posted by Edgemeal
    This example shows how to launch an exe and close it,
    http://support.microsoft.com/kb/q129797/
    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

  8. #8
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    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.

  9. #9

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    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
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  10. #10
    PowerPoster CDRIVE's Avatar
    Join Date
    Jul 2007
    Posts
    2,620

    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
    I've edited that post and inserted the module.
    Last edited by CDRIVE; Aug 19th, 2008 at 06:10 PM.
    <--- 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??

  11. #11

    Thread Starter
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    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
  •  



Click Here to Expand Forum to Full Width