ERRORLEVEL 
Author Message
 ERRORLEVEL

is there a way in which you could return a DOS ERRORLEVEL from a VBScript?
basically i want to run a vbscript in a login script batch file. the script
will only run depending on the ERRORLEVEL which is returned. thanks

Steve



Wed, 19 Nov 2003 18:23:40 GMT  
 ERRORLEVEL
WScript.Quit ERRORLEVEL  ' (Subject to bugs)

WSH Documentation
http://msdn.microsoft.com/scripting/windowshost/wshdoc.exe
http://msdn.microsoft.com/scripting/windowshost/docs/reference/defaul...

=-=-=
Steve
-=-=-


Quote:
> is there a way in which you could return a DOS ERRORLEVEL from a vbscript?
> basically i want to run a vbscript in a login script batch file. the
script
> will only run depending on the ERRORLEVEL which is returned. thanks

> Steve



Wed, 19 Nov 2003 20:17:19 GMT  
 ERRORLEVEL

Quote:
> WScript.Quit ERRORLEVEL  ' (Subject to bugs)

Here's the corrolary:  Can a batch file return an error level to my script?


Sat, 22 Nov 2003 00:36:32 GMT  
 ERRORLEVEL

Quote:


> > WScript.Quit ERRORLEVEL  ' (Subject to bugs)

> Here's the corrolary:  Can a batch file return an error level to my script?

To set errorlevel to 0 via batch I use the FIND command as follows...

  echo 0 | FIND "0" > NUL

Errorlevel 1:

  echo 1 | FIND "0" > NUL

Since this works in all common MS OSes it is the most robust method
I can think of. (Alternatively, you can use CHOICE which is standard
only under Windows 9x.)

HTH

--
    __ _  _
   |_ |_)(__                       http://www.fpschultze.de
___|  | ____)chultze_________________________________________________
                                I am logged in, therefore I am.



Sat, 22 Nov 2003 00:59:17 GMT  
 ERRORLEVEL

Quote:
> To set errorlevel to 0 via batch I use the FIND command as follows...

>   echo 0 | FIND "0" > NUL

> Errorlevel 1:

>   echo 1 | FIND "0" > NUL

Ah, but how do I then read the errorlevel in the script that called the
batch file?


Sat, 22 Nov 2003 03:36:38 GMT  
 ERRORLEVEL


Quote:


> Ah, but how do I then read the errorlevel in the script that called the
> batch file?

That is a good question. (I am new to this WSH stuff, you should know.)
Assuming, you use the Run method to execute a batch file within your
script I suggest experimenting with this method's fourth parameter:

<quote from WSH reference>
If bWaitOnReturn is set to TRUE, the Run method returns any error
code returned by the application.
</quote from WSH reference>

VBS Example:

  set oSh = CreateObject("WScript.Shell")
  Return = oSh.Run("%COMSPEC% /C batfile.bat",,TRUE)

HTH

--
    __ _  _
   |_ |_)(__                       http://www.fpschultze.de
___|  | ____)chultze_________________________________________________
                                I am logged in, therefore I am.



Sat, 22 Nov 2003 04:36:57 GMT  
 ERRORLEVEL

Quote:


> > WScript.Quit ERRORLEVEL  ' (Subject to bugs)

> Here's the corrolary:  Can a batch file return an error level to my

script?

Dim ErrorLevel
Set WshShell = WScript.CreateObject("WScript.Shell")
ErrorLevel = WshShell.Run ("%comspec% /c your.bat",,True)

You need to set the bWaitOnReturn argument True to get the errorlevel from
the program.

There is a problem with Win9x. COMMAND.COM doesn't return the errorlevel
from the batch file. As far as it's concerned, even though the batch
encountered an error, it didn't; it terminated normally. You'll always get a
return of 0 for batch files in Win9x. You will get the correct errorlevel
for other programs.

ErrorLevel = WshShell.Run ("your.exe",,True)

=-=-=
Steve
-=-=-



Sat, 22 Nov 2003 04:48:11 GMT  
 ERRORLEVEL
that is exactly what i was after, thanks.

Quote:
> WScript.Quit ERRORLEVEL  ' (Subject to bugs)

> WSH Documentation
> http://msdn.microsoft.com/scripting/windowshost/wshdoc.exe
> http://msdn.microsoft.com/scripting/windowshost/docs/reference/defaul...

> =-=-=
> Steve
> -=-=-



> > is there a way in which you could return a DOS ERRORLEVEL from a
vbscript?
> > basically i want to run a vbscript in a login script batch file. the
> script
> > will only run depending on the ERRORLEVEL which is returned. thanks

> > Steve



Sat, 22 Nov 2003 05:48:52 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. VBScript and errorlevel

2. Ending VB with an errorlevel

3. How to get an Errorlevel

4. ErrorLevel

5. FTP and ERRORLEVEL on Windows 2000

6. Errorlevel from scripting

7. Passing errorLevel ?

8. Environment Variable %ErrorLevel%

9. Wscript.quit and ERRORLEVEL

10. Testing Errorlevel in WSH

11. Detecting a runtime error with %errorlevel%

12. Errorlevel

 

 
Powered by phpBB® Forum Software