Solved

How to open wshell in dos window?

Posted on 2008-10-22
5
396 Views
Last Modified: 2012-06-27
I have created many vbs scripts in the past that when double clicked, run within the command prompt window and I can see the output and progress.

I am now running the same scripts on a new server and instead of the command prompt window opening, I am getting the windows message window, with the typical OK button, which I have to press to proceed. This is very annoying.

What do I need to change to make these run within the command prompt window?

I read somewhere that CScript would do this, but as I said, this works as desired on other windows boxes, why not this one?
Set wShell = CreateObject("WScript.Shell")
 
WScript.Echo "hello world"
 
wshell.run "%comspec% /c AddWindowsUser.bat " & "hello world", 0, True
 
Wscript.Echo "user added" & vbcrlf & vbcrlf

Open in new window

0
Comment
Question by:juliandormon
  • 4
5 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 22778240
The default engine on the other boxes may be cscript - that's a registry setting...
You can either change the registry, or try this code to ensure it's run with cscript:
(place it just after your assignment of wShell)
If Lcase(Right(wscript.fullname,11))="wscript.exe" Then
  strPath=wscript.ScriptFullName
  strCmd = "%comspec% /k cscript " & chr(34) & strPath & chr(34)
  WShell.Run strCmd, 0
  wscript.quit
End If

Open in new window

0
 
LVL 67

Expert Comment

by:sirbounty
ID: 22778266
The registry change is located at HKCU\VBSFile\Shell\Open\Command
The default is normally %SystemRoot%\System32\Wscript.exe "%1" %*
but you can easily change it to cscript.exe
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 22778271
And http://support.microsoft.com/default.aspx/kb/952033 details the change as well...
0
 

Author Comment

by:juliandormon
ID: 22778405
Thanks a bunch!
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 22778413
Happy to help - thanx for the grade! :^)
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question