Getting the Returnvalue of an application started from VB
Hi out there,
I created a VB-program that calls another application via shellexecute.
That app is a backup program, that gets commandline parameters from my VB-program.
Now sometimes the backup program crashes, and the backup files are not correctly finished or incomplete.
The backup program delivers a returnvalue that is 0 when it completes the backup successfully, if the value is <> 0 the backup failed.
The returnvalue of Shellexecute AFAIK delivers only Information about the execution of the command, so it does not help.
But then how can I get the returnvalue of the application in VB?
Re: Getting the Returnvalue of an application started from VB
You can use SendMessage API from your backup program to notify the main app.
Re: Getting the Returnvalue of an application started from VB
Hi Shaikh.Riyaz.a,
seems I did not make it clear:
The Backup Program is a 3rd Party tool. We bought it.
My program calls that backup program with user-specific commandline-parameters
AFAIK sendmessage could be used if I could change the code of the backup Program, or am I missing something?
Re: Getting the Returnvalue of an application started from VB
Here's how to trap the return code...
Code:
Option Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Const SW_SHOWNORMAL As Long = 1
Private Const SW_HIDE As Long = 0
Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Dim sSave As String, Ret As Long
Private Sub Form_Load()
'KPD-Team 1998
'URL: http://www.allapi.net/
'E-Mail: [email protected]
Dim sSave As String, Ret As Long
'Create a buffer
sSave = Space(255)
'Get the system directory
Ret = GetSystemDirectory(sSave, 255)
'Remove all unnecessary chr$(0)'s
sSave = Left$(sSave, Ret)
End Sub
Private Sub Command1_Click()
Dim d As Long
d = ShellExecute(Me.hwnd, "Open", sSave & "CMD.exe", " /c dir c: > c:\Myfile.txt", "c:\", SW_SHOWNORMAL)
MsgBox d
End Sub
Re: Getting the Returnvalue of an application started from VB
Quote:
Originally Posted by Patzer
The Backup Program is a 3rd Party tool. We bought it.
My program calls that backup program with user-specific commandline-parameters
Then right now in what format does it return the success or failure of its own? I mean how come you know that it ran successfully?
Re: Getting the Returnvalue of an application started from VB
Re: Getting the Returnvalue of an application started from VB
If you don't want to use On Error Goto YourErrorCode
to check for crash.
d will return the following value.
Code:
Private Sub Command1_Click()
Dim d As Long
d = ShellExecute(Me.hwnd, "Open", sSave & "CMD.exe", " /c dir c: > c:\Myfile.txt", "c:\", SW_SHOWNORMAL)
MsgBox d
' The return values (d=...) are;
' <=32 ' = Some type of error.
' > 32 ' = OK. No error
' = 0 ' = Operating system is out of memory.
' = 2 ' = File (CMD.exe) was not found.
' =42 ' = Found and ran without any errors.
' See URL; http://allapi.mentalis.org/apilist/ShellExecute.shtml
' for more information.
End Sub