Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7928293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:41:40+00:00 2026-06-03T19:41:40+00:00

Say I have a batch file where in I call a VBScript(which returns the

  • 0

Say I have a batch file where in I call a VBScript(which returns the ERRORLEVEL) like:

    @echo off
    echo Passing the control to VBSCript.
    Cscript test.vbs
    if %ERRORLEVEL% EQU 0 (
    echo done here!!!!
    EXIT /B 0
    )
    if %ERRORLEVEL% EQU 1
    echo EROOR!!!!!!!
    EXIT /B 1
    )

and the test.vbs is like:

    Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
    strComputer = "."
    strKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
    strEntry1a = "DisplayName"
    strEntry1b = "QuietDisplayName"
    strEntry1c = "DisplayVersion"
    .......................................
    ..........some code here...............
    .......................................
    IF i=0 THEN
    WScript.Echo "Congratulations!! Everything is fine......
    WScript.Quit 0
    ELSE
    WScript.Echo "Sorry Mate.. Things out here look bad....
    WScript.Quit 1
    END IF

My question is that upon execution of this batch file…….. I am not able to catch the %ERRORLEVEL% generated by my VBScript in my batch script(PS: test.vbs is executing fine when ran individually). Moreover , its a weird output I am getting:

    Passing the control to VBSCript.
    Microsoft (R) Windows Script Host Version 5.7
    Copyright (C) Microsoft Corporation. All rights reserved.

    ............................
    ............................
    ......VB Code Running........
    ..........here.............

    0 was unexpected at this time.

why am I getting “0 was unexpected at this time.” error in Batch file.
How else can I pass Error code from a vbscript to its parent batch script??

Any help is welcome…….
Thanks in advance.


New Edit ,

Thanks PA for your reply..
Actually now I am setting a different variable namely, ERRORLEV as shown below:

      IF ERRORLEVEL 0 SET /a ERRORLEV=0
      IF ERRORLEVEL 1 SET /a ERRORLEV=1
      IF ERRORLEVEL 2 SET /a ERRORLEV=2
      echo the value of ERRORLEV is :
      echo %ERRORLEV%
      if %ERRORLEV% EQU 0 (
      echo Nothing is to be Done
      EXIT /B 0
      )
      IF %ERRORLEV% EQU 2 (
      echo Let start then.......
      EXIT /B 1
      )

The best part is now event the variable ERRORLEV is getting set/echoed correctly.
However I am not able to use it in ‘IF’ command..
I am getting a output of :

      the value of ERRORLEV is :
      2
      0 was unexpected at this time.

Can you suggest , what might be the case???

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T19:41:41+00:00Added an answer on June 3, 2026 at 7:41 pm

    As stated in HELP IF

    ERRORLEVEL number – Specifies a true condition if the last program run
    returned an exit code equal to or greater than the number
    specified.

    so you need to test ERRORLEVEL with this special syntax.

    IF ERRORLEVEL 2 DOTHIS &goto :eof
    IF ERRORLEVEL 1 DOTHAT &goto :eof
    DOGOOD
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let say ,I have a batch file and I have three commands like: Execute
Let's say I have a batch file that has padding in it, and I
I have this batch file which needs to do some stuff in a folder.
Let's say, the user drag and drops an file into my batch file, which
I have a batch file with an external configuration file. Say I needed to
This is a very specific question, however; Say I have a batch file running
Say I have a batch file for carrying out a long build and at
I would like to run batch file to rename all FOLDERS ONLY. Let's say,
I have a sql script say abc.sql which I am calling from a batch
I have a batch file that outputs a list of commands which themselves can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.