I have a vb6 program that ftp's a text file from a server to the mainframe. The vb program executes a .cmd file that references a .txt file with a put statement. I put code in my cmd file to show me what the return code is. The ftp is completing successfully and giving a return code of 0, but my vb program is giving me a return code of 1. My code is as follows:
**************In General Declarations:
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type
Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Public Const PROCESS_QUERY_INFORMATION = &H400
Public Const STILL_ACTIVE = &H103
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&
Private Declare Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Long, ByVal bInheritHandle _
As Long, ByVal dwProcessID As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal _
hObject As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" _
(ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" _
(ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Function CreateProcessBynum Lib "kernel32" _
Alias "CreateProcessA" (ByVal lpApplicationName As String, _
ByVal lpCommandLine As String, ByVal lpProcessAttributes As Long, _
ByVal lpThreadAttributes As Long, ByVal bInheritHandles As Long, _
ByVal dwCreationFlags As Long, lpEnvironment As Any, _
ByVal lpCurrentDirectory As String, lpStartupInfo As STARTUPINFO, _
lpProcessInformation As PROCESS_INFORMATION) As Long
Private Declare Sub ExitProcess Lib "kernel32" (ByVal uExitCode As Long)
********In main sub:
sFTPCmd = "\\servername\folder\sharefolder\FTP.CMD"
RetVal = ExecCmd(sFTPCmd)
'If return code not 0 display msg and end program
If RetVal <> 0 Then
MsgBox "FTP not successful RC = " & RetVal
cnnSB.Close
'ExitProcess RetVal
End
End If
**********************
Public Function ExecCmd(cmdline As String) As Long
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
Dim ret&
start.cb = Len(start)
start.lpReserved = vbNullString
start.lpDesktop = vbNullString
start.lpTitle = vbNullString
start.dwFlags = 0
'Start the shelled application:
ret = CreateProcessBynum(cmdline, vbNullString, 0, 0, True, NORMAL_PRIORITY_CLASS, ByVal 0&, _
vbNullString, start, proc)
'Wait for the shelled application to finish
Call WaitForSingleObject(proc.hProcess, INFINITE)
Call CloseHandle(proc.hThread)
Call CloseHandle(proc.hProcess)
ExecCmd = ret
End Function
*********************
I start out with a return code of zero; after the CreateProcessBynum I have a return code of 1.
Any suggestions would be greatly appreciated.
**************In General Declarations:
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type
Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Public Const PROCESS_QUERY_INFORMATION = &H400
Public Const STILL_ACTIVE = &H103
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&
Private Declare Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Long, ByVal bInheritHandle _
As Long, ByVal dwProcessID As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal _
hObject As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" _
(ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" _
(ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Function CreateProcessBynum Lib "kernel32" _
Alias "CreateProcessA" (ByVal lpApplicationName As String, _
ByVal lpCommandLine As String, ByVal lpProcessAttributes As Long, _
ByVal lpThreadAttributes As Long, ByVal bInheritHandles As Long, _
ByVal dwCreationFlags As Long, lpEnvironment As Any, _
ByVal lpCurrentDirectory As String, lpStartupInfo As STARTUPINFO, _
lpProcessInformation As PROCESS_INFORMATION) As Long
Private Declare Sub ExitProcess Lib "kernel32" (ByVal uExitCode As Long)
********In main sub:
sFTPCmd = "\\servername\folder\sharefolder\FTP.CMD"
RetVal = ExecCmd(sFTPCmd)
'If return code not 0 display msg and end program
If RetVal <> 0 Then
MsgBox "FTP not successful RC = " & RetVal
cnnSB.Close
'ExitProcess RetVal
End
End If
**********************
Public Function ExecCmd(cmdline As String) As Long
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
Dim ret&
start.cb = Len(start)
start.lpReserved = vbNullString
start.lpDesktop = vbNullString
start.lpTitle = vbNullString
start.dwFlags = 0
'Start the shelled application:
ret = CreateProcessBynum(cmdline, vbNullString, 0, 0, True, NORMAL_PRIORITY_CLASS, ByVal 0&, _
vbNullString, start, proc)
'Wait for the shelled application to finish
Call WaitForSingleObject(proc.hProcess, INFINITE)
Call CloseHandle(proc.hThread)
Call CloseHandle(proc.hProcess)
ExecCmd = ret
End Function
*********************
I start out with a return code of zero; after the CreateProcessBynum I have a return code of 1.
Any suggestions would be greatly appreciated.