Nunya Business
Nunya Business

Reputation: 1

Call a new batch file or add VB script?

What I have below allows a user to enter the name of a device, from a batch Menu, which will then telnet in a new command window and automatically log them in. After the below batch runs I then want the user to be prompted for a new variable (Host). Once the user enters the new variable (Host) I want the batch to continue on, within the same window, and ping the new variable (Host).

I tried the call command but it opens a new window every which way i try it. Do I need a vbscript? I'm a bit lost.

@echo off
:A
color 0A
Cls
echo.
echo.
echo.
echo Putty SSH
echo.
echo.
echo.
set /p computer=HOST:
start putty.exe -ssh xxxxxx@%computer% -pw xxxxxx
goto:options

Example of what I want to come next. I do not know how to add the lines below to the batch script above and make them execute in the window opened by "start putty.exe -ssh xxxxxx@%computer% -pw xxxxxx. I want the %computer% to be a new variable. Not from the variable in the batch above.

"

set /p computer=HOST:
ping %computer%

Upvotes: 0

Views: 139

Answers (1)

user2299169
user2299169

Reputation:

Sadly there's no way to do this from batch files. As soon as you "call a command" from a batch it is considered as something independent from the rest of your batch calls either executed previously or will execute later.

I'd recommend creating a vbs file even on the first go and use that for all the operations you want.

Here's a little sample code for you to see how to 'manage' a command window you started up from your vbs:

Option Explicit

Dim oShell

Set oShell = CreateObject("WScript.Shell") 
REM 1 == windowstate normal, false==don't wait for app to finish running
Call oShell.Run ("cmd /K CD C:\", 1, false)
Call WScript.Sleep (300)

REM you don't need it right after cmd.exe started up as it'll be
REM focused/activated by OS but may need later
REM Call oShell.AppActivate ("cmd.exe")

Call oShell.SendKeys ("echo yay! {ENTER}")

SET oShell = Nothing

You can find a list of commands you may use with 'SendKeys' function: http://msdn.microsoft.com/en-us/library/8c6yea83%28v=vs.84%29.aspx

Hope this helps!

Upvotes: 1

Related Questions