How can I execute an .exe file from a vb application in windows 2000?

gmvist
gmvist used Ask the Experts™
on
How can I execute an .exe file from vb and also know when the execution is terminated?
Do you know other instructions than "shell"???
It seems that in win2000 shell doesn't work.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Guy Hengel [angelIII / a3]Billing Engineer
Most Valuable Expert 2014
Top Expert 2009

Commented:
Software Team Lead
Commented:
See if these helps:

Shell to Another Application and Wait Until it Finishes:
http://www.freevbcode.com/ShowCode.Asp?ID=99

Wait for Shell Call to Complete:
http://www.freevbcode.com/ShowCode.Asp?ID=3441

Shell to another app and wait for it to finish using Windows Scripting Host:
http://www.freevbcode.com/ShowCode.Asp?ID=219

regards

Commented:
gmvist,

Here is the way that I do it:

Public Declare Function CreateProcessA Lib "kernel32" (ByVal lpApplicationName As Long, 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 Long, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
Public Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Public 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

Public Type PROCESS_INFORMATION
   hProcess As Long
   hThread As Long
   dwProcessID As Long
   dwThreadID As Long
End Type

Public Const NORMAL_PRIORITY_CLASS = &H20&
Public Const INFINITE = -1&



Public Sub RunExe(byVal WhatFile as string)
   
    Dim Proc As PROCESS_INFORMATION
    Dim Start As STARTUPINFO
    Dim Ret As Long
   

    Start.cb = Len(Start)
   
     'Start the executable
    Ret = CreateProcessA(0&, WhatFile, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, 0&, 0&, Start, Proc)        
        'Wait for it to close
    Ret = WaitForSingleObject(Proc.hProcess, INFINITE)
        'Release it
    Ret = CloseHandle(Proc.hProcess)
       
End Sub

The only other thing that I have added sometimes is a timer or invoking the sleep() function to give the started app a few seconds to get up and running.  Hope this works, I have had success using it on all OS's.

G
Author of the Year 2009

Commented:
Hi gmvist,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept ryancys's comment(s) as an answer.

gmvist, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept THIS comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial