Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

run an exe and get confirmation at the end

Posted on 2002-07-16
3
Medium Priority
?
133 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 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…
Suggested Courses

916 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