Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Other Programming > VBScript
VBScript For questions and discussions related to VBScript.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VBScript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old February 4th, 2005, 12:00 PM
Registered User
Join Date: Jan 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Getting info from comand line prompt

I use Input boxes for all my vbscript INPUT (normally).

I have a case in which i'm converting a rexx script to vbscript and
rexx allows you to display info to and pull info from the command prompt. How so I get INFO from the command line.

I know that you can pass args to the script when it is first invoked but how do I say "get info after a Wscript.echo command"


Randy Dray
Reply With Quote
  #2 (permalink)  
Old February 16th, 2005, 12:40 PM
Friend of Wrox
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts

What is the sequence of events here? What is displayed on the command screen? How is the text on the command screen put there?

Here is something you can use to pass a command to comspec (CMD in all versions of Windows) and retrieve text that is sent back from the app. In this case, Ping is called, and the script checks to see if there is a reply. This will work on a Private Class C using 192.168.0 as the subnet, and it will ping 10 addresses in this range. You can substitute a strAddress from your own subnet, and your own counter range.

Dim strAddress1
Dim strAddress
Dim i

i = 1

strAddress = "192.168.0."
strAddress1 = strAddress & i

Do Until i = 11
    Set objShell = CreateObject("WScript.Shell")
    Set objExecObject = objShell.Exec _
    ("%comspec% /c ping -n 3 -w 1000 " & strAddress1)
        Do While Not objExecObject.StdOut.AtEndOfStream
            strText = objExecObject.StdOut.ReadAll()
            If InStr(strText, "Reply") > 0 Then
            WScript.Echo strAddress1 & " - Reply received."
            WScript.Echo strAddress1 & " - No reply received."
            End If
    i = i + 1
    strAddress1 = strAddress & i

This script returns this information on my network (of course I changed the real subnet):

Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved. - Reply received. - Reply received. - Reply received. - Reply received. - Reply received. - Reply received. - Reply received. - Reply received. - Reply received. - Reply received.
Exit code: 0 , 0000h

I hope this gets you started.

Reply With Quote
  #3 (permalink)  
Old February 17th, 2005, 07:41 AM
Friend of Wrox
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post

if your script is run from the DOS prompt,i.e. using cscript not wscript, then you need:

I use this general function in my scripts:
Function GetUserInput(sPrompt)

     If GetRunMode() = 0 Then
         GetUserInput = InputBox(sPrompt)
         WScript.StdOut.Write sPrompt
         GetUserInput = WScript.StdIn.ReadLine()
     End If

End Function

you'll also need this referenced function

Function GetRunMode()

    ' determines if script running under windows or command-line
    ' returns 0 for Win, non-0 for Cmd
    GetRunMode = InStr(1, WScript.FullName, "cscript.exe", 1)

End Function
Reply With Quote

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to draw indicator line in owc line chart AlexOo General .NET 0 July 9th, 2007 10:32 PM
C++ Pause comand line ZORCH C++ Programming 3 June 20th, 2007 09:28 AM
How to read file line by line in EVC++ iriskab Visual C++ 0 September 27th, 2006 01:39 PM
Reading line by line from a .txt file x_ray VB.NET 2002/2003 Basics 5 February 10th, 2006 01:55 PM
Where would I get info on how to download info aidanc ASP.NET 1.x and 2.0 Application Design 1 September 29th, 2003 02:45 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.