Results 1 to 5 of 5

Thread: Shell Execute

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2004
    Posts
    14

    Shell Execute

    Hello,
    We have two separate VB applications and i would like to join these two applications and would like to start the second application from the first one. I am using the Shell command to execute the Exe of the second one but my problem is i want to start the second application in a silent mode without the frontend of the first application and there is a ok button on the second application. So how can i tell my program to move to the OK button code.

    Thanks in advance

    reg
    vbs

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Shell Execute

    I think we need to do this step by step.
    Quote Originally Posted by vbs
    Hello,
    We have two separate VB applications
    So far so good
    Quote Originally Posted by vbs
    and i would like to join these two applications
    What do you mean by "join"
    Quote Originally Posted by vbs
    and would like to start the second application from the first one. I am using the Shell command to execute the Exe of the second one
    From the first one I presume
    Quote Originally Posted by vbs
    but my problem is i want to start the second application in silent mode without the front end of the first application
    Here is where you lost me. If you don't have the front end of the first one how are you planning on shelling the second one?

    You have application A.exe and application B.exe

    A.exe shells B.exe - now what?

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2004
    Posts
    14

    Re: Shell Execute

    HI,
    Thanks for your reply. I am sorry about the text which i had written earlier.
    My application which i have written has a frontend and when i click a button on my application it should start the second application(written by my collegue) which also has a gui with a ok button andwhen a user clicks the ok button then a process of the second application starts so i do not want to display the frontend from the second application but want to ensure that the ok button click happens in the background may be by the first program itself.....

    Hope that i have been able to explain a bit more.

    Thanks again.

    Best regards,
    vbs

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

    Re: Shell Execute

    So if you know the name of the process that B.exe is executing then you can possible look for that process in the running processes list in a timer event and when found kill the timer and continue on with your A.exe program.
    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

  5. #5
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Shell Execute

    If I've understood you correctly you want to launch an application in the background and then press a button, to make that application do something.

    The easiest way would be to get your collegue to modify their program to allow a command line argument which will automatically run the process.

    If you need to do it yourself then something like this should work:

    VB Code:
    1. Private Declare Function GetDesktopWindow Lib "user32" () As Long
    2.  
    3. Private Declare Function GetWindow Lib "user32" ( _
    4.                 ByVal hwnd As Long, _
    5.                 ByVal wCmd As Long) As Long
    6.                
    7. Private Declare Function GetWindowThreadProcessId Lib "user32" ( _
    8.                 ByVal hwnd As Long, _
    9.                 lpdwProcessId As Long) As Long
    10.  
    11. Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" ( _
    12.                 ByVal hWnd1 As Long, _
    13.                 ByVal hWnd2 As Long, _
    14.                 ByVal lpsz1 As String, _
    15.                 ByVal lpsz2 As String) As Long
    16.  
    17. Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
    18.                 ByVal hwnd As Long, _
    19.                 ByVal wMsg As Long, _
    20.                 ByVal wParam As Long, _
    21.                 ByVal lParam As Long) As Long
    22.  
    23. Private Const GW_CHILD = 5
    24. Private Const GW_HWNDNEXT = 2
    25. Private Const WM_LBUTTONDOWN = &H201     'Button down
    26. Private Const WM_LBUTTONUP = &H202       'Button up
    27.  
    28. Private Sub Command1_Click()
    29.     Dim lngHandle1 As Long
    30.     Dim lngButtonHdl As Long
    31.     lngHandle1 = pID2hWnd(Shell("AppB.exe", vbHide))
    32.  
    33.     If (lngHandle1 > 0) Then
    34.         PressHandle FindWindowEx(lngHandle1, 0&, "Button", "OK")
    35.     End If
    36. End Sub
    37.  
    38. Private Function pID2hWnd(ByVal pID As Long) As Long
    39.     'the Shell() function returns the Process ID (PID) for the newly spawned
    40.     'process. Below we loop through every top-level window, get it's PID and
    41.     'compare it to the one returned by the Shell() function. If it's the same,
    42.     'we've found the window-handle (hWnd) to it!
    43.     Dim lngHandle As Long, lngProcID As Long
    44.     lngHandle = GetDesktopWindow
    45.     lngHandle = GetWindow(lngHandle, GW_CHILD)
    46.     Do
    47.         If GetWindowThreadProcessId(lngHandle, lngProcID) <> 0 Then
    48.             If lngProcID = pID Then
    49.                 pID2hWnd = lngHandle
    50.                 Exit Do
    51.             End If
    52.         End If
    53.         lngHandle = GetWindow(lngHandle, GW_HWNDNEXT)
    54.     Loop Until lngHandle = 0
    55. End Function
    56.  
    57. Private Sub PressHandle(ByVal lHandle As Long)
    58.   Dim lParam As Long
    59.   lParam = MAKELONG(10, 5)
    60.   SendMessage lHandle, WM_LBUTTONDOWN, 0, lParam
    61.   SendMessage lHandle, WM_LBUTTONUP, 0, lParam
    62. End Sub
    63.  
    64. Private Function LOWORD(ByVal dw As Long) As Integer
    65.   If dw And &H8000& Then LOWORD = dw Or &HFFFF0000 Else LOWORD = dw And &HFFFF&
    66. End Function
    67.  
    68. Private Function MAKELONG(wLow As Long, wHigh As Long) As Long
    69.   MAKELONG = LOWORD(wLow) Or (&H10000 * LOWORD(wHigh))
    70. End Function

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