Solved

run an exe and get confirmation at the end

Posted on 2002-07-16
3
123 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now