Can anybody enlighten me as to why my shell and wait function returns file not found error?
Code:Option Explicit ''' ************************************************************************* ''' Module Constant Declaractions Follow ''' ************************************************************************* ''' Constant for the dwDesiredAccess parameter of the OpenProcess API function. Private Const PROCESS_QUERY_INFORMATION As Long = &H400 ''' Constant for the lpExitCode parameter of the GetExitCodeProcess API function. Private Const STILL_ACTIVE As Long = &H103 ''' ************************************************************************* ''' Module Variable Declaractions Follow ''' ************************************************************************* ''' It's critical for the shell and wait procedure to trap for errors, but I ''' This variable is used to pass error ''' messages between procedures. Public gszErrMsg As String ''' ************************************************************************* ''' Module DLL Declaractions Follow ''' ************************************************************************* 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 Public Sub DemoShellAndWait() On Error GoTo ErrorHandler ''' Clear the error mesaage variable. gszErrMsg = vbNullString ''' Notification that the Integration is about to begin. MsgBox "You are about to Send This Confirmation Via Echosign To the Desired Recipient.", vbInformation, "Echosign API Integration" ''' Shell out to the Echosign. If Not bShellAndWait("C:\Documents and Settings\ben barnes\Desktop\CSharp\demo.bat http://www.example.com/services/Echo...umentService11 IQKL5CXI6V2C4W send C:\Documents and Settings\ben barnes\Desktop\Echo.bat [email protected] ") Then Err.Raise 9999 ''' This message box will not display until you have dismissed the shell. MsgBox "You have finished sending this confirmation via Echosign.", vbInformation, "Shell and Wait Demo" Exit Sub ErrorHandler: ''' If we ran into any errors this will explain what they are. MsgBox gszErrMsg, vbCritical, "Shell and Wait Demo" End Sub ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ''' Comments: Shells out to the specified command line and waits for it to ''' complete. The Shell function runs asynchronously, so you must ''' run it using this function if you need to do something with ''' its output or wait for it to finish before continuing. ''' ''' Arguments: szCommandLine [in] The command line to execute using Shell. ''' iWindowState [in] (Optional) The window state parameter to ''' pass to the Shell function. Default = vbHide. ''' ''' Returns: Boolean True on success, False on error. ''' ''' Date Developer Action ''' -------------------------------------------------------------------------- ''' 05/19/05 Ben Barnes Created ''' Private Function bShellAndWait(ByVal szCommandLine As String, Optional ByVal iWindowState As Integer = vbHide) As Boolean Dim lTaskID As Long Dim lProcess As Long Dim lExitCode As Long Dim lResult As Long On Error GoTo ErrorHandler ''' Run the Shell function. lTaskID = Shell(szCommandLine, iWindowState) ''' Check for errors. If lTaskID = 0 Then Err.Raise 9999, , "Shell function error." ''' Get the process handle from the task ID returned by Shell. lProcess = OpenProcess(PROCESS_QUERY_INFORMATION, 0&, lTaskID) ''' Check for errors. If lProcess = 0 Then Err.Raise 9999, , "Unable to open Shell process handle." ''' Loop while the shelled process is still running. Do ''' lExitCode will be set to STILL_ACTIVE as long as the shelled process is running. lResult = GetExitCodeProcess(lProcess, lExitCode) DoEvents Loop While lExitCode = STILL_ACTIVE bShellAndWait = True Exit Function ErrorHandler: gszErrMsg = Err.Description bShellAndWait = False End Function




Reply With Quote