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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running scripts in Cscript vs. Wscript

Status
Not open for further replies.

pghsteelers

Technical User
Apr 21, 2006
121
US
I am trying to run a script so that it runs cscript rather than wscript. However, I would like to have it bring up a command-line prompt requesting a user to input an IP address, then the script runs as I have scripted it using that input in the same command-line prompt. Is that possible?

Currently, it brings up a windows "input" box and then for every peice of info returned it will put that into a display in a windows message box. I would rather use run this in cscript and display the user input question and return info in a command-line prompt.
 
you can grab stdin using cscript.exe i am sure.
if not then you can still run cscript.exe and stick with your InputBox method but instead of using Msgbox use Wscript.Echo and this will chuck stdout to the console window, hope this helps
 
well to give a little more information. I have Microsoft's scriptomatic 2.0. Basically if not familar it already has some pre-written code to do some general information gathering. To save some time, I am wanting to implement the script with a few changes such as giving the end-user a prompt to input what they want the script to run on. Then output that information.

However, Scriptomatic 2.0 if ran within itself, runs the scripts in cscript for you. However, I have natively on my own machine set to wscript by default. So for example, if I run the same script outside of scriptomatic it will run in wscript.

So how can I make a script run in cscript just like the "scriptomatic 2.0" does even though I have defaulted to run .vbs files in wscript. I need to turn this vbs over to someone and I don't want to require that they change their default to way windows runs .vbs files.

Is there a way to dictact in a .vbs how it will be ran?
 
This is the function that I use to ensure a script is running with the appropriate host. Just call it at the start of the script. Note that it will not work with a script that takes arguments on the command line. That is a simple change to the function but I have not had time to make it yet.

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''
'' Function: EnsureRunningUnder strInt, nWindowType
'' Purpose: Ensures that the script is being run with the specified
'' interpreter.
'' Takes: strInt - A string specifying the interpreter to use.
'' valid strings are "cscript" or "wscript"
'' nWindowType - An int specifying the window behavior of
'' the process that will be created. This is passed
'' directly to the .Run method of the WScript.Shell
'' object. See the WSH documentation for valid values.
'' Returns: NOTHING
'' ToDo: Make it handle script arguments
''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub EnsureRunningUnder(strInt, nWindowType)
Dim oWsh:Set oWsh = CreateObject("WScript.Shell")
Dim strThisScript
Dim strRunCommand
Dim strIntPath
Dim strRunningInt
Dim arrIntPathParts

Select Case UCase(strInt)
Case "WSCRIPT", "WSCRIPT.EXE"
strInt = "wscript.exe"
Case "CSCRIPT", "CSCRIPT.EXE"
strInt = "cscript.exe"
Case Else
Exit Sub
End Select

arrIntPathParts = Split(WScript.FullName, "\")
strRunningInt = arrIntPathParts(UBound(arrIntPathParts))
arrIntPathParts(UBound(arrIntPathParts)) = ""
strIntPath = Join(arrIntPathParts, "\")
If UCase(strInt) <> UCase(strRunningInt) Then
strRunCommand = strIntPath & strInt & " " & Chr(34) & WScript.ScriptFullName & Chr(34)
oWsh.Run strRunCommand, nWindowType, False
WScript.Quit
End If
End Sub 'EnsureRunningUnder

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top