error level checking in a vbscript

Posted on 2006-04-21
Last Modified: 2008-01-09
Hello all,

I have a .vbs script that launches a DOS application which,  the writer of the application tells me,  sets errorlevel to 0 if it runs sucessfully and a 1 in not run sucessfully.

My goal is to find a snippet of vbscript which checks for the value of errorlevel and then does something based on the value.

I am launching the dos based applicaion from my .vbs script using the following lines .....

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run <the location and name of the dos executable goes here>, 1, True

I'm pretty new to vbscript so,  "simple is greatly appreciated".

Thanks in advance.
    LVL 85

    Accepted Solution

    How about...

    Dim WshShell, oExec
    Set WshShell = CreateObject("WScript.Shell")

    Set oExec = WshShell.Exec("InsertFullPathToYourExeInHere")

    Do While oExec.Status = 0
       WScript.Sleep 100

    Select Case oExec.ExitCode
       Case 0
          ' do something...
       Case 1
          ' do something else...
    End Select
    LVL 1

    Author Comment

    by:Accidental Hyper-V Administrator

    Thanks a million. (Or at least 500)


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    Title # Comments Views Activity
    tenRun challenge 28 67
    post4 challenge 28 69
    zeroFront challenge 7 58
    mergeTwo  challenge 13 53
    I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
    This article will show, step by step, how to integrate R code into a R Sweave document
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    759 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

    11 Experts available now in Live!

    Get 1:1 Help Now