我在下面的内容允许用户从批处理菜单中输入设备的名称,然后在新的命令窗口中远程登录并自动登录。在下面的批处理运行后,我希望用户成为提示输入新变量(Host)。一旦用户输入新变量(主机),我希望批次在同一窗口内继续,并ping新变量(主机)。
我尝试了call命令但是每次尝试它都会打开一个新窗口。我需要一个vbscript吗?我有点失落。
@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
我想接下来的例子。我不知道如何将以下行添加到上面的批处理脚本中,并使它们在“start putty.exe -ssh xxxxxx @%computer%-pw xxxxxx”打开的窗口中执行。我希望%computer%成为新的变量。不是来自上面批次中的变量。
“
set /p computer=HOST:
ping %computer%
答案 0 :(得分:1)
遗憾的是,没有办法从批处理文件中执行此操作。 只要您从批处理中“调用命令”,它就会被视为独立于先前执行或稍后执行的其余批处理调用的内容。
我建议即使是第一次创建vbs文件,也可以将其用于所需的所有操作。
以下是一些示例代码,供您查看如何“管理”您从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
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
您可以找到可与“SendKeys”功能一起使用的命令列表: http://msdn.microsoft.com/en-us/library/8c6yea83%28v=vs.84%29.aspx
希望这有帮助!