Can not run CScript or WScript on XP Pro command prompt

C

cjeffwang

I am reviewing WSH and VBScript programming.

With a statement: WScript.Echo "Hello World!" , in my HelloWscript.vbs
file, I had no problem running this file by double-clicking on it.
However, on the command prompt, typing either CScript HelloWScript or
WScript HelloWScript.vbs returned the same error message:

CScript/WScript is not recognized as an internal or external command,
operable program or batch file.

I just upgraded XP Home to XP Pro. Does XP Pro support WSH command
prompt?

TIA,
Jeffrey
 
S

Shenan Stanley

I am reviewing WSH and VBScript programming.

With a statement: WScript.Echo "Hello World!" , in my HelloWscript.vbs
file, I had no problem running this file by double-clicking on it.
However, on the command prompt, typing either CScript HelloWScript or
WScript HelloWScript.vbs returned the same error message:

CScript/WScript is not recognized as an internal or external command,
operable program or batch file.

I just upgraded XP Home to XP Pro. Does XP Pro support WSH command
prompt?

Sounds like your path is messed up.
At the same command prompt, type:

path

and press ENTER.

is "C:\WINDOWS\system32" in there?
 
W

Wesley Vogel

Place HelloWScript.vbs in %windir% or %windir%\system32.
Open a command prompt and type:

HelloWScript

Hit Enter

or this in a command prompt...
WScript "%windir%\system32\HelloWScript.vbs"
both will display...
---------------------------
Windows Script Host
---------------------------
Hello World!
---------------------------
OK
---------------------------

CScript "%windir%\system32\HelloWScript.vbs"
in a command prompt will echo Hello World! in the command prompt window.

--
Hope this helps. Let us know.

Wes
MS-MVP Windows Shell/User

In
 
C

cjeffwang

At the same command prompt, type:
path and press ENTER.
is "C:\WINDOWS\system32" in there?

Yes, mine is c:\WINXP\Systems32
Place HelloWScript.vbs in %windir% or %windir%\system32.
Open a command prompt and type:
HelloWScript Hit Enter

Popup dialog created. Typing Hello and HelloWSH showed 'Not Recognized'
error.
CScript "%windir%\system32\HelloWScript.vbs"
in a command prompt will echo Hello World! in the command prompt window.

Yes, Popup dialog created.

At my C:\Script\WSH command, typing Hello, HelloWSH, or HelloWScript
now show the popup dialog.

I am totally confused. One thing I did, which is different from the
book, is I have had 3 Hello files with
3 different names, i.e. Hello.vbs, HelloWSH.vbs for WScript Shell, and
HelloWScript for WScript.Ech.
Is this the reason why the WScript and CScript commands are not
working?
 
W

Wesley Vogel

I have no idea what the extension .ech is for.

Is C:\Script\WSH in your PATH?

Open a command prompt, type: path and hit Enter.

At a minumum it should have these
PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem
and you need to add C:\Script\WSH if that's where you are storing your
practice scripts.

See this on how to add to the PATH...
HOW TO Manage Environment Variables in Windows XP
http://support.microsoft.com/default.aspx?scid=kb;en-us;310519

Or move your scripts to a folder that is already listed in PATH.

[[The PATH environment variable defines the Windows NT search path. The
search path is a list of directories that are searched when the command
shell attempts to locate an executable file.

The PATHEXT environment variable defines the list of file extensions
checked by Windows NT when searching for an executable file. Like the PATH
variable, semi-colons separate individual items in the PATHEXT variable.
The default value of PATHEXT is .COM;.EXE;.BAT;.CMD. ]]
http://www.microsoft.com/technet/archive/winntas/deploy/shellscr.mspx

You can also open a command prompt, type: set and hit Enter to see both
PATH & PATHEXT.

--
Hope this helps. Let us know.

Wes
MS-MVP Windows Shell/User

In
 
C

cjeffwang

I finally figured it out.

With 3 Hello files: Hello.vbs, HelloWSH.vbs, and HelloWScript on my
C:\WINXP\WSH directory,
double-clicking or typing Hello, HelloWSH, or HelloWScript showed Hello
World ! popup dialog.
Coping HelloWScript vbs file i.e. WScript.Echo "Hello world!" to
C:WINXP\SYSTEM32, then
typing WScript HelloWScript.vbs showed popup dialog; while typing
CScrpt HelloWScript.vbs
showed only Hello World ! on the Windows console.

Thank you all.
-- Jeffrey
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top