Capture return code from Shell App

Posted on 2005-04-05
Last Modified: 2010-11-11

The FTPS (MOVEit Freely Secure FTP) Application that is called in the Shell() below will return an error code (0 if successful). How can I capture the return code that FTPS returns?

        Dim ProcID
        ' Execure Secure FTP
        ProcID = Shell("FTPS -e:on -z -s:""C:\HCC_Upload_Files\FtpUploadScript.TXT""", AppWinStyle.NormalFocus, True, 120000)

Question by:bobbailey22
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    Don't use Shell().  Instead use the Process() class:

        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            Dim p As Process
            p = Process.Start("FTPS -e:on -z -s:""C:\HCC_Upload_Files\FtpUploadScript.TXT""")
            Dim exitCode As Integer = p.ExitCode
            MsgBox("exitCode = " & exitCode)
        End Sub

    Author Comment


    I was really excited about your solution (love learning new stuff) but I keep getting the following error when the Process.Start line is executed...

    An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in system.dll
    Additional information: The system cannot find the file specified

    I also tried qualifying the executable like so...

    p = Process.Start("""C:\Program Files\MOVEit\FTPS.exe"" -e:on -z -s:""C:\HCC_Upload_Files\FtpUploadScript.TXT""")

    but got the same error.

    I know the text file path and name are good.

    Any Ideas????
    LVL 85

    Accepted Solution

    Here is an alternate usage that may work for you:

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim p As New Process
            p.StartInfo.FileName = "C:\Program Files\MOVEit\FTPS.exe"
            p.StartInfo.Arguments = "-e:on -z -s:""C:\HCC_Upload_Files\FtpUploadScript.TXT"""
            Dim exitCode As Integer = p.ExitCode
            MsgBox("exitCode = " & exitCode)
        End Sub


    Author Comment

    You are awesome! If I could give you an A+++ I would.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
    Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    731 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now