Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does this VBScript give me an error?

Tags:

vbscript

I saved this VBScript script to my local machine as c:\test.vbs:

WScript.StdOut.WriteLine "This is a test"

When I run it from the command line, I get this error:

---------------------------
Windows Script Host
---------------------------
Script: C:\test.vbs
Line:   1
Char:   1
Error:  The handle is invalid. 
Code:   80070006
Source:     (null)

---------------------------
OK   
---------------------------

I get this under Windows Vista (SP1) and Windows XP Pro (SP3).

like image 965
JosephStyons Avatar asked Apr 21 '09 19:04

JosephStyons


1 Answers

This link may help you:

http://www.tech-archive.net/Archive/Scripting/microsoft.public.scripting.vbscript/2004-07/0979.html

It appears that the handle StdOut is only available when using a console host (cscript.exe) and not a windowed host (wscript.exe). If you want the code to work, you have to use cscript.exe to run it.

The post also describes how to change default behavior to run scripts with cscript and not wscript.

like image 199
Scott M. Avatar answered Oct 12 '22 18:10

Scott M.