Solved

run an exe and get confirmation at the end

Posted on 2002-07-16
3
127 Views
Last Modified: 2010-05-02
Hi.

I need an API function, code or shell function that launchs an application (exe), and returns a confirmation of a succesful (or failure) termination.
i tried to use shell, but it returns a "good" start...
boaZone
0
Comment
Question by:boaZone
  • 2
3 Comments
 
LVL 22

Expert Comment

by:rspahitz
ID: 7157606
Dim dblRet as double
dblRet = Shell("command-line proces to launch")
if dblRet = 0 then
  msgbox "Command failed"
else
  msgbox "command launched successfully"
endif

From MS Help:
"[Shell] Runs an executable program and returns a Variant (Double) representing the program's task ID if successful, otherwise it returns zero."

If you're looking for when the shell completes, that must be done through an API: OpenProcess, GetExitCodeProcess, CloseHandle

Private Declare Function OpenProcess Lib "kernel32" _
  (ByVal dwDesiredAccess As Long, _
   ByVal bInheritHandle As Long, _
   ByVal dwProcessId As Long) 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

0
 
LVL 27

Accepted Solution

by:
Ark earned 105 total points
ID: 7158825
Hi
The easiest way is to use WScript library:

Dim WshShell As Object
Set WshShell = CreateObject("WScript.Shell")
Return = WshShell.Run("calc.exe", 1, TRUE)

Where:
Return - return error code if any
"calc.exe" - exe name to start
1 - window stile (=vbNormalFocus)
TRUE - Wait when finished


If you prefer pure API code, there are tons of "Shell and wait" samples over the web. IMHO the best and well documented is from Karl E. Peterson VB Guru:
http://www.mvps.org/vb/code/Shell32.zip

Cheers
0
 
LVL 27

Expert Comment

by:Ark
ID: 7158942
Thanks for points, glad I could help you
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Excel object stays open 19 73
I need help formating a date variable in my VB.Net application 2 51
Hide vba in gp 7 94
Recommendation vb6 to vb.net or others 14 142
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question