This page is edited from the 1cmdfaq.txt faq-file contained in
my tscmd.zip
command line interface (CLI) collection. That zipped file has much
additional material, including a number of detached .cmd script
files. It is recommended that you also get the zipped version as a
companion.
Please see "
The Description and
the Index page" for the conditions of usage and other such
information.
161} How do I test that the Windows Script Host is available?
@echo off & setlocal enableextensions
echo Wscript.Echo "@set WSHavailable=1">"%temp%\test$$.vbs"
cscript /nologo "%temp%\test$$.vbs" > "%temp%\test$$.bat"
for %%c in (call del) do %%c "%temp%\test$$.bat"
del "%temp%\test$$.vbs"
if not "%WSHavailable%"=="1" (echo Windows Script Host is not not available & goto :EOF)
echo Windows Script Host is available, continuing
rem Whatever
endlocal & goto :EOF
Or, simply
@echo off & setlocal enableextensions
cscript>nul
if %errorlevel% NEQ 0 goto :EOF
echo Windows Script Host is available, continuing
rem Whatever
endlocal & goto :EOF
Or even just
@echo off & setlocal enableextensions
cscript>nul||goto :EOF
echo Windows Script Host is available, continuing
rem Whatever
endlocal & goto :EOF
Or, with a subroutine
@echo off & setlocal enableextensions
call :checkVBS status
if not defined status (
echo.&echo Windows Script Host is not not available, exiting
goto :EOF)
echo Continuing whatever
endlocal & goto :EOF
::
:: ==========================================================
:: Subroutine: Check whether Windows Script Host is available
:checkVBS
setlocal enableextensions
>"%temp%\tmp$$$.vbs" echo WScript.Echo "VBSfound"
for /f %%a in ('cscript //nologo "%temp%\tmp$$$.vbs"') do (
set found_=%%a>nul)
for %%f in ("%temp%\tmp$$$.vbs") do if exist %%f del %%f
endlocal & set "%1=%found_%" & goto :EOF
The output might be:
C:\_D\TEST>cmdfaq
Continuing whatever
or
C:\_D\TEST>cmdfaq
'cscript' is not recognized as an internal or external command,
operable program or batch file.
Windows Script Host is not not available, exiting