Question

I have been trying to create a batch file(s) that triggers my Windows 8 PC to begin shutting down after 30 seconds has elapsed and that also has a warning message: "Your PC will shutdown in 30 seconds! Please press Cancel button to abort Shutdown." I have created the following batch files on my desktop:

shutdown /s /c "Your PC will shutdown in 30 seconds! /t 30

and:

shutdown /a

and it does shutdown the pc, but the message will not show until exactly 30 seconds later and goes away within 1 second and starts shutting down with no way to stop it. I have even tried to do the shutdown /a batch file before the 30 seconds is up with no luck in stopping the shutdown.

Is the commands not correct for Windows 8?

I would like to have one script with the popup message warning and with a cancel (abort) button prior to the 30 seconds expiring or at least get the 2 batch files to work in Windows 8 with a warning message and the abort batch file both working.

Not sure if Windows 8 has a command or something that works but would like to get it working. Any help is so greatly appreciated!!!

Thanks you very much!

Billy

Était-ce utile?

La solution 2

Try

@echo off
echo Your PC will shutdown in 30 seconds! Press CTRL+C to abort.
ping -n 31 127.0.0.1>nul
shutdown /s

The PING command is a secure way of pausing the batch script for desired amount of time. More info here: How to wait in a batch script?

Pressing Ctrl-C will abort a batch script from continuing.

Autres conseils

This is somewhat easier and has been kitchen tested in Windows 8.

:: Shutdown.bat
:: Messages a forced shutdown then waits for a Ctrl+C to abort,
:: any key to execute immediately, or shuts all programs and  
:: the computer down after Timeout /t (n) seconds automatically.
:: 
@echo off
echo.
echo.
:: 
echo Press Ctrl+C to Abort imminent Shutdown because I'm
timeout /t 120
::
shutdown.exe /s /t 5
exit

Hi you can try this,

@echo off
echo "Your System will shutdown in 30 seconds. To abort press A"
SET Option=Choice:
if "%Option%"=="A" GOTO Sub_MenuA
shutdown /s
:Sub_MenuA
exit 0

Hi try this small clever code which i created and have used task scheduler which is fun to use.

title GO HOME
@echo off
:MAIN
echo.
echo.
echo.
echo Do you wanna shut down?
echo.
echo The time is %time%
echo.
echo.
echo.
echo.
set /p input= y or n?     
if %input%==n goto work
if %input%==y call bye.bat

:work
echo.
echo.
echo.
echo. Alright, keep working busy bee.

TIMEOUT 5

Create one more bat file and save as bye.bat and copy paste this code:

echo Have a nice evening, Cya.

shutdown.exe /s /t 0

Here is another option. This BAT file asks the user a YES/NO question to determine if the shutdown should continue. No need for the user to press CTRL+C to abort. The Shutdown will not continue until the user enters a choice.

@ECHO OFF
:: This batch file allows the user to choose to shutdown immediately, or cancel and   return to Windows
::
CD\
CLS
ECHO.
:LOOP
ECHO Would you like to shutdown immediately?
ECHO.
ECHO   Y = SHUTDOWN IMMEDIATELY (WARNING!! Unsaved work will be lost)
ECHO   N = CANCEL and return to Windows
ECHO.
SET Choice=
SET /P Choice=TYPE YOUR CHOICE AND PRESS ENTER: 
IF NOT '%Choice%'=='' SET Choice=%Choice:~0,1%
ECHO.
IF '%Choice%'=='y' GOTO ShutdownNow
IF '%Choice%'=='n' GOTO Leave
ECHO "%Choice%" is not valid. Please try again.
ECHO.
GOTO Loop
:ShutdownNow
ECHO.
shutdown /s /t 1

:Leave
Exit
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top