Solved

run an exe and get confirmation at the end

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

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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

733 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