Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

run an exe and get confirmation at the end

Posted on 2002-07-16
3
Medium Priority
?
132 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 28

Accepted Solution

by:
Ark earned 420 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 28

Expert Comment

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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

670 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