Reading the return value from Main() in VbScript,Batch File,PowerShell Script

by jask2002 18. October 2012 01:50

Main() method in C# can have either (void or int) as the return value


namespace TestSolution
    class Program
        static void Main(string[] args)



namespace TestSolution
    class Program
        static int Main(string[] args)
            return 1001;

At this point the question arises in my mind is how to read the return value from the Main() when called from any script VBscript or batch file or PowerShell?

Here is the solution


iRetVal = 0
SPath = "\Scripts\TestSolution.exe"
iRetVal = oShell.Run (sPath,0,TRUE)
msgbox iRetVal
If iRetVal = 1001 then
          ' DO something
          ' Do something else
End if


Batch File

rem test.bat
@echo off
@if "%ERRORLEVEL%" == "1001" goto good

    echo Execution Succeded
    echo return value = %ERRORLEVEL%
    goto end



PS C:\Users\jaskis\Documents\Visual Studio 2010\Projects\TestSolution\TestSolution\bin\Debug> .\TestSolution.exe
PS C:\Users\jaskis\Documents\Visual Studio 2010\Projects\TestSolution\TestSolution\bin\Debug> $lastexitcode

PayPal — The safer, easier way to pay online. Has this post helped you? Saved you? If you'd like to show your appreciation. Please buy me a coffee or make a small contribution toward blog's maintenance(to keep it Ads free )

Tags: , , ,

.Net | C#

Comments (2) -

mac wholesale cosmetics
mac wholesale cosmetics United States
10/29/2014 11:27:34 PM #

Its arduous to find educated individuals on this subject, but you sound like you understand what you�re talking about! Thanks Mac Makeup online


Terese Poynter
Terese Poynter United States
4/19/2015 3:51:43 AM #

A motivating discussion is worth comment. There's no doubt that that you need to publish more on this issue, it may not be a taboo matter but usually people do not talk about these subjects. To the next! All the best!!


Pingbacks and trackbacks (1)+

Add comment

  Country flag

  • Comment
  • Preview

Tag cloud

Month List


Comment RSS



The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.