|
-
March 5th, 2008, 08:28 AM
#1
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?
have a nice day
Patzer
_____________________________
Philo will never be forgotten
-
March 5th, 2008, 08:48 AM
#2
Re: Getting the Returnvalue of an application started from VB
You can use SendMessage API from your backup program to notify the main app.
-
March 5th, 2008, 09:17 AM
#3
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?
have a nice day
Patzer
_____________________________
Philo will never be forgotten
-
March 5th, 2008, 05:24 PM
#4
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
-
March 6th, 2008, 01:52 AM
#5
Re: Getting the Returnvalue of an application started from VB
 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?
-
March 6th, 2008, 01:41 PM
#6
Re: Getting the Returnvalue of an application started from VB
It doesn't crash?
-
March 8th, 2008, 06:05 AM
#7
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
Don't spend too much time on your computer.
Sit on a chair instead!!
It's a lot more comfortable and better for your hardware.
:-/ 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|