Solved

How to open wshell in dos window?

Posted on 2008-10-22
5
393 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now