Click to See Complete Forum and Search --> : VBScript/Windows Scripting Host shell


Chamitha
January 19th, 2003, 10:56 PM
Hi,
I'm a newbie to VBScript and I'm trying to launch an application using the WScript.Shell Run command.

Option Explicit
Dim WshShell
Dim return

Set WshShell = Wscript.CreateObject("Wscript.Shell")
return = WshShell.Run("cmd.exe")
MsgBox(return)
set WshShell = Nothing

I have a couple of questions.

1. How can I capture the return code of the Run command. Although I have used the variable return to capture the code it only displays a message box if the Run command was successful. Otherwise a WSH error message is displayed and script terminates.

2. How can I surpress the WSH error messages? Basically I want my script to capture and handle the return codes of functions without the Windows SCripting Host throwing messages!

If there is any other object other than WScript which can do the same in VBScript please let me know. Thanks!

columbus2003
January 20th, 2003, 02:07 AM
1) if you want to have the command's return code, you need to wait until it finishes. To wait a process, set third parameter of run method true. (e.g. return = WshShell.Run("cmd.exe", 1, true)

2)To overwrite default error msg, use "error handling" feature. (ref: On Error statement)