Link to home
Start Free TrialLog in
Avatar of gmvist
gmvist

asked on

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

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.
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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