Re: Working with a .exe file

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



I think the trouble might be that Shell doesn't wait till the .exe is fully launched, so
your next code line doesn't target the .exe.
Try to launch your .exe with this code:


Option Explicit
Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type

Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadId As Long
End Type

Private Declare Function WaitForSingleObject _
Lib "kernel32" (ByVal hHandle As Long, _
ByVal dwMilliseconds As Long) As Long

Private Declare Function CreateProcessA _
Lib "kernel32" (ByVal lpApplicationName As String, _
ByVal lpCommandLine As String, _
ByVal lpProcessAttributes As Long, _
ByVal lpThreadAttributes As Long, _
ByVal bInheritHandles As Long, _
ByVal dwCreationFlags As Long, _
ByVal lpEnvironment As Long, _
ByVal lpCurrentDirectory As String, _
lpStartupInfo As STARTUPINFO, _
lpProcessInformation As PROCESS_INFORMATION) As Long

Private Declare Function GetExitCodeProcess _
Lib "kernel32" (ByVal hProcess As Long, _
lpExitCode As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" _
(ByVal hObject As Long) As Long
Private Const NORMAL_PRIORITY_CLASS = 32


Sub test()

'experiment with the 1000 as you may need less or even 0
ExecCmd "C:\WINDOWS\SYSTEM32\notepad.exe", 1000, True

End Sub


Function ExecCmd(sCmdLine As String, _
lmSecsWait As Long, _
Optional bShowWindow As Boolean) As Long

'will start an external process and
'wait till this process is finished
'returns > -1 if successfull and -1 if not
'-----------------------------------------
Dim proc As PROCESS_INFORMATION
Dim Start As STARTUPINFO
Dim lReturn As Long

'Initialize the STARTUPINFO structure:
With Start
.cb = Len(Start)
.dwFlags = 1 'hexadecimal would be &H1
If bShowWindow Then
.wShowWindow = 1
End If
End With

'Start the shelled application:
lReturn = CreateProcessA(sCmdLine, _
vbNullString, _
0, _
0, _
1, _
NORMAL_PRIORITY_CLASS, _
0, _
vbNullString, _
Start, _
proc)

'Wait for the shelled application to finish:
lReturn = WaitForSingleObject(proc.hProcess, lmSecsWait)
GetExitCodeProcess proc.hProcess, lReturn
CloseHandle proc.hThread
CloseHandle proc.hProcess
ExecCmd = lReturn

End Function


RBS


"Marco" <marcomarranc@xxxxxxxxx> wrote in message news:1173175385.315031.300610@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi all,

I have a software ending with .exe that i would like to open, type
the
word 'select' on it, press 'enter' and make it run.


I used the following code :


wb = Shell("Y:\Programs\Sel.exe", 1)
Application.Wait Now() + TimeValue("00:00:15")

SendKeys "select"
SendKeys "{ENTER}"

but the Sel.exe either copies the text "select" on my vbe editor
or shows the text "select" but it doesn't
recognize it.
When I open Sel.exe and I type "select" + "{ENTER}", without using vba
code,it works.

Any helps?


Thanks,
Marco


.



Relevant Pages

  • Re: Working with a .exe file
    ... lpReserved As String ... Private Declare Function WaitForSingleObject _ ... Lib "kernel32" (ByVal lpApplicationName As String, ... Dim lReturn As Long ...
    (microsoft.public.excel.programming)
  • RE: waiting for an .exe file that runs
    ... I accomplish to make an .exe file run but the call sub i've written ... lpReserved As String ... Private Declare Function WaitForSingleObject _ ... Dim lReturn As Long ...
    (microsoft.public.excel.programming)
  • waiting for an .exe file that runs
    ... I accomplish to make an .exe file run but the call sub i've written ... lpReserved As String ... Private Declare Function WaitForSingleObject _ ... Dim lReturn As Long ...
    (microsoft.public.excel.programming)
  • Re: Working with a .exe file
    ... lpReserved As String ... Private Declare Function WaitForSingleObject _ ... Lib "kernel32" (ByVal lpApplicationName As String, ... Dim lReturn As Long ...
    (microsoft.public.excel.programming)
  • Re: AX Controls
    ... If you want to determine the Path of the hosting Exe from within ... Private Declare Function GetModuleFileNameA Lib "kernel32" _ ... Private Declare Function GetModuleHandle Lib "kernel32" Alias _ ... "GetModuleFileNameA" (ByVal hModule As Long, ByVal lpFileName As String, ...
    (microsoft.public.vb.general.discussion)