|
-
Mar 6th, 2006, 10:32 AM
#1
Thread Starter
New Member
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
-
Mar 6th, 2006, 10:37 AM
#2
Re: Shell Execute
I think we need to do this step by step.
 Originally Posted by vbs
Hello,
We have two separate VB applications
So far so good
 Originally Posted by vbs
and i would like to join these two applications
What do you mean by "join"
 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
 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?
-
Mar 6th, 2006, 11:38 AM
#3
Thread Starter
New Member
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
-
Mar 6th, 2006, 11:43 AM
#4
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 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 
-
Mar 6th, 2006, 03:01 PM
#5
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:
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetWindow Lib "user32" ( _
ByVal hwnd As Long, _
ByVal wCmd As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" ( _
ByVal hwnd As Long, _
lpdwProcessId As Long) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" ( _
ByVal hWnd1 As Long, _
ByVal hWnd2 As Long, _
ByVal lpsz1 As String, _
ByVal lpsz2 As String) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Private Const GW_CHILD = 5
Private Const GW_HWNDNEXT = 2
Private Const WM_LBUTTONDOWN = &H201 'Button down
Private Const WM_LBUTTONUP = &H202 'Button up
Private Sub Command1_Click()
Dim lngHandle1 As Long
Dim lngButtonHdl As Long
lngHandle1 = pID2hWnd(Shell("AppB.exe", vbHide))
If (lngHandle1 > 0) Then
PressHandle FindWindowEx(lngHandle1, 0&, "Button", "OK")
End If
End Sub
Private Function pID2hWnd(ByVal pID As Long) As Long
'the Shell() function returns the Process ID (PID) for the newly spawned
'process. Below we loop through every top-level window, get it's PID and
'compare it to the one returned by the Shell() function. If it's the same,
'we've found the window-handle (hWnd) to it!
Dim lngHandle As Long, lngProcID As Long
lngHandle = GetDesktopWindow
lngHandle = GetWindow(lngHandle, GW_CHILD)
Do
If GetWindowThreadProcessId(lngHandle, lngProcID) <> 0 Then
If lngProcID = pID Then
pID2hWnd = lngHandle
Exit Do
End If
End If
lngHandle = GetWindow(lngHandle, GW_HWNDNEXT)
Loop Until lngHandle = 0
End Function
Private Sub PressHandle(ByVal lHandle As Long)
Dim lParam As Long
lParam = MAKELONG(10, 5)
SendMessage lHandle, WM_LBUTTONDOWN, 0, lParam
SendMessage lHandle, WM_LBUTTONUP, 0, lParam
End Sub
Private Function LOWORD(ByVal dw As Long) As Integer
If dw And &H8000& Then LOWORD = dw Or &HFFFF0000 Else LOWORD = dw And &HFFFF&
End Function
Private Function MAKELONG(wLow As Long, wHigh As Long) As Long
MAKELONG = LOWORD(wLow) Or (&H10000 * LOWORD(wHigh))
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|