批处理文件中的Jscript

时间:2016-11-10 14:21:07

标签: batch-file jscript

我想在bat文件中运行以下代码:

@echo off
echo ---------------------------------
ping -n 1 google.com | find "TTL=" >nul
if errorlevel 1 (
    echo google = OFFLINE
) else (
    echo google = ONLINE
)

然后我希望下面的代码也会在if errorlevel 1中运行:

WshShell.AppActivate "Mozilla Firefox"
WshShell.SendKeys "google Offline"
WshShell.SendKeys "{ENTER}"

如何运行上面的代码?
最后一个代码通常在vbs扩展名中运行,但我想在bat扩展名中运行。

1 个答案:

答案 0 :(得分:2)

这是“Frankenscript”;我喜欢这样一个词! ;)

@set @a=0; /*
@echo off
ECHO --------------------------------- 
ping -n 1 google.com | find "TTL=" >nul 
if errorlevel 1 (
   echo google = OFFLINE
   cscript //nologo //E:JScript "%~F0"
   if NextSection == JScript (      */
      WshShell = WScript.CreateObject("WScript.Shell");
      WshShell.AppActivate("Mozilla Firefox");
      WshShell.SendKeys("google Offline");
      WshShell.SendKeys("{ENTER}"); /*
   )
) else ( 
   echo google = ONLINE
)
rem */