Not sure this is doable but I'm trying to write the following batch script in a single line:
@echo off
echo Shutdown initiated...
echo.
choice /c xy /n /t 10 /d y /m "To cancel shutdown press "X""
if errorlevel 2 goto EXEC
if errorlevel 1 goto ABORT
:EXEC
echo.
echo Computer shutting down
timeout /t 10
exit
:ABORT
echo.
echo Shutdown cancelled
timeout /t 10
exit
The above script needs to be passed via the vbs run command into cmd. The following is the closest I can get it:
option explicit
dim wshell, strcmd
set wshell = createobject("wscript.shell")
if hour(now()) >= 0 and hour(now()) < 6 then
strcmd = "cmd /c @echo off & echo ""Pre-Dawn Shutdown initiated"" & echo. & choice /c xy /n /t 10 /d y /m ""To cancel shutdown press ""X"""" & if errorlevel 2 goto exec & if errorlevel 1 goto abort & :exec & echo. & echo ""Computer shutting down"" & timeout /t 10 & exit & :abort & echo. & echo ""Shutdown cancelled"" & timeout /t 10 & exit"
wshell.run strcmd
end if
The above works as expected up until the choice command is reached then the script fails to execute the remainder correctly. Any help in resolving this is very much appreciated.