Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't switch default scripting host to cscript 1

Status
Not open for further replies.

grittyminder

IS-IT--Management
Oct 18, 2005
53
JP
Hi all,

I need help with a problem that doesn't make any sense. I can't seem to switch the default scripting host to cscript. The way this is normally done is via the following command:

wscript //H:cscript

When I run this command I see something similar to "the default script host was set to cscript"; however, the scripting host remains to be wscript (e.g. when I run WScript.FullName I get back c:/Windows/System 32/WScript.exe).

I also tried changing the default script host using a script (e.g. oShell.Run "cscript """ & WScript.ScriptFullName & """", 1, False) but that doesn't seem to work either.

Having wscript.echo'ed text pop up whenever I run a script is driving me nuts. Please help!
 
[0] It means it has changed the default action of the file-association with the .vbs or .js or .wsf. Those are taken as executable.

[1] In the commandprompt, you'll observe these resulting behaviour.

[tt]c:\>wscript //h:cscript
c:\>wscript xyz.vbs [green]still hosted by wscript[/green]
c:\>cscript xyz.vbs [green]still hosted by cscript[/green]
c:\>xyz.vbs [green]it will be hosted by cscript[/green]
c:\>cscript //h:wscript
[green]or c:\>wscript //h:wscript both has the same effect[/green]
c:\>xyz.vbs [green]it will be hosted by wscript[/green]
[/tt]
[2] And the change will be effecting double-click as well and that's the consequence of what it means by changing the "default script host".
 
Thank you for your reply.

Okay, so what should I do next then? I already mentioned that changing the default script host via "wscript //h:cscript" doesn't seem to be working. Of course, when I run a script directly using the cscript host (e.g. "cscript myscript.vbs") the script host used is cscript, as would be expected.
 
Okay, I think that this is a very confusing situation.

So I was slightly mistaken--I was poking around (more specifically, I used the script given at this link: and discovered that the default scripting host is in fact set to cscript. However. When I run a VB script the WScript Echo method does not output to the command console as is expected. Rather, all output is generated inside annoying graphical pop ups.

According to the Echo method documentation at MSDN ( "The Echo method behaves differently depending on which WSH engine you are using." Specifically, CScript generates output on the command line; WScript generates output in graphical message boxes (i.e. annoying pop up boxes).

So if the default script host is set to cscript, why is wscript being used by default whenever I run a VB script?!? (And for the record, I am not using the MsgBox function or anything silly like that.)
 
My post of 19 Apr 10 2:29 does not show you the behaviour anticipate? Has the prejudice of being silly and annoying kept you from seeing?
 
Hi Tsuji, I don't think I understand you.

The situation is that the default script host is set to cscript. However when I run a script from the command-line as is (i.e. not being prefaced with "cscript" or the like) all text passed to the WScript Echo method is being displayed in graphical pop up boxes, which implies that wscript is being used for some reason instead of the default (i.e. cscript).

My assumption is that WScript is taking precedence over the default, CScript, when a VB Script is run. As to how or why this is happening, I do not know. My assumption could also be wrong.
 
How about the successive commands run in my post of 19 Apr 10 1:59?
 
Okay, I see now. Here is what I get when I running each of the following commands:

> c:\>wscript //h:cscript

The default script host is set to cscript.

> c:\>wscript xyz.vbs still hosted by wscript

WScript.Echo outputs text in a graphical pop up (as expected).

> c:\>cscript xyz.vbs still hosted by cscript

WScript.Echo outputs text to the command line (as expected).

> c:\>xyz.vbs it will be hosted by cscript

WScript.Echo outputs text in a graphical pop up (NOT expected).

> c:\>cscript //h:wscript or c:\>wscript //h:wscript both has the same effect

The default script host is set to wscript.

> c:\>xyz.vbs it will be hosted by wscript

WScript.Echo outputs text to the command line!!! (NOT expected).

Whoa, so what is going on here? It seems that wscript and cscript have been switched someplace? This is highly, highly unusual...

Okay, so how do I fix this?
 
The verifying can be done via gui or registry. I suggest via gui here.

[1]In your windows explorer, click:
menu:Tools > Folder Options > tab:File Types
[2] There you pull the select box until you find vbs file type...
select:Extension vbs>button: Advanced
[3] You'll see all the actions. The bold will be the default action. It will probably shows you "open" but that is not generic. It can be renamed to any other name. In any case, choose the default action and click on the edit button.
select: default action > button: edit (click)
[4] There, the application action line should show you the "default" host. If you anticipate wscript, it will show something like this, if you've 9x, xp, ... (some other version of os may show winnt instead of windows, sure common sense).
[tt] C:\WINDOWS\System32\WScript.exe "%1" %*[/tt]
[5] If you really see cscript.exe instead, then change it to wscript.exe when at that time you have just run //h:wscript.
[6] There may be other action, non-default, which shows the action with cscript.exe. You can access them via right-click context-menu. But, now, it suffices to check what kinds of anomalies are there and correct therefrom, if any.

Check it out first.
 
I followed your instructions and I think I see what is wrong.

It appears that when "wscript //H:cscript" is run the default action for .VBS is set to "open" (i.e. wscript). When I run "wscript //H:wscript" the default action changes to "open with command prompt" (i.e. cscript). I tried switching the default actions (i.e. change "open" to the default action for wscript, etc.) but they would just switch back again. I suppose these "default" default actions might be defined someplace in the registry?

Anyhow, what I ended up doing is changing the default action for "open" and "open with command prompt" to cscript and wscript respectively, and everything is running smooth and as expected now.

Cool Tsuji, thanks for you help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top