C:\_G\WWW\~ELISANET\INFO\tscmd161.html
<http://www.elisanet.fi/tsalmi/info/tscmd161.html>
Copyright © 2003- by Prof. Timo Salmi  
Last modified Fri 30-Nov-2018 11:58:22

 
Assorted NT/2000/XP/.. CMD.EXE Script Tricks
From the html version of the tscmd.zip 1cmdfaq.txt file
To the Description and the Index
 

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

References/Comments: (If a Google message link fails try the links within the brackets.)
  Google Groups Dec 2 2007, 12:03 am [M]

[Previous] [Next]

C:\_G\WWW\~ELISANET\INFO\tscmd161.html
C:\_G\WWW\~ELISANET\FTPCMD\TSALMI.CMD /tscmd161
http://www.elisanet.fi/tsalmi/info/tscmd161.html
file:///c:/_g/www/~elisanet/info/tscmd161.html