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!

Trying to access a Command Prompt via VBS 1

Status
Not open for further replies.

HerbAndEdnaWeinstein

Technical User
Apr 30, 2003
104
US
Hi, I've never used VBScript before. I'm just trying to figure out why this code does not start calc.exe. I'm sure it's something very, very basic.

I'm trying to run this .vbs, by the way, by double clicking on it from the desktop.

Thanks for your time,
hw

**********************

Sub CommandLine()

set sa = createobject ("Shell.Application")

sa.FileRun(calc.exe)

End Sub

**********************
 
I figured out the syntax:

Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("calc")

But I still have a question: How can I get the console to actually come up on screen as it's executing, and not close out instantly as it finishes? It would help me a lot with debugging.
 
Try this:
Code:
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "calc",1,True
WScript.Echo "Calc finished"


Hope This Help
PH.
 
PHV,

Thank you for replying.

However, what I'm trying to get is this:

When the vbs is invoked, a command prompt comes up. Inside the command prompt, calc.exe is run. The command prompt stays up even after the script is done.

rs

 
Try to launch your script with wscript instead of cscript.

Hope This Help
PH.
 
This is the entire file:

*********************************************

Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("calc")

*********************************************

Thanks,
rs
 
When I launch your script with wscript, I've no command prompt at all.
When I launch it with cscript, I get a command prompt that disappear shortly after the calc window comes up.
Anyway, to get rid of them, you can try to add this after the Exec call:
Code:
WScript.Quit

Hope This Help
PH.
 
Hello all,

The behavior of exec and run is different.

Try to run:
Code:
Dim WshShell
Set WshShell=CreateObject("WScript.Shell")
WshShell.Run "%comspec% /K %windir%\calc.exe"
Set WshShell=Nothing

regards - tsuji
 
Hi all
Have a try on this :

Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")
'The tool is launched
Set oExec = WshShell.Exec("calc.exe")

'Wait for the end of process
Do While oExec.Status = 0
WScript.Sleep 100
Loop

Wscript.Echo "Finished"
 
Hello all,

I actually have nothing to add. I just have occasion to verify some features in various OS that intrigued me. (My own posting up there is far from perfect.)

If I understand the original posting correctly, I am under the impression that the purpose is to get A. calc.exe gui and B. commandprompt both available with one single run or exec line. Rough equivalent to two lines:
WshShell.Run "%comspec% /K"
WshShell.Run "calc.exe"
These two lines will be the simplest solution.

What intrigues me is the different aspects (after leaving aside the calc.exe resides in %windir%\system32 in win2k up):
[1] WshShell.Run "%comspec% /K calc.exe"
For win9x and winMe, the command prompt window is opened up and fully operative.
For win2k, the cmd window is quitted. It just leave its window for inspection.
This is an unanticipated aspect.

[2] WshShell.Run "calc.exe && %comspec% /K"
This syntax works for win2k.
But, it is not acceptable for win9x, winME.

Just make a quick note here for the record.

- tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top