Jump to content

Recommended Posts

Posted (edited)

Its Friday and i'm trying to create a script to shutdown the machines using the choice command to give a option to cancel.

 

Heres what ive got

@echo off
choice /c:YN /n /m "This computer will shutdown in 2 minutes.  Would you like to cancel this shutdown? Y to Cancel" /t:1 /d:N
if errorlevel 2 (shutdown /s -t 0 -f) else  echo. && echo Restart Canceled for 30 minutes.

 

If I press Y then it cancels the shutdown. If I leave it to timeout it enters N but doesn't shutdown

If I echo the errorlevel when N is pressed then 2 comes out.

 

 

The cancel option works great but the shutdown option just repeats the script.

 

Anyone able to help?

Edited by DCUK6
Posted

Something like this should work, if no input detected after 120 seconds it will shut down the PC.

 

@echo off

choice /C YN /D Y /T 120 /M "Shutdown [Y] Yes or [N] No?"

IF errorlevel 2 goto shutdown_no

IF errorlevel 1 goto shutdown_yes

 

:shutdown_no

 

exit

 

:shutdown_yes

 

shutdown /f /s /t 300 /c "Computer Shutting Down in 5 Minutes"

Posted

Thanks cscc,

 

I've found the shutdown command in a bat file requires you to run as administrator.

 

Just running the shutdown command doesn't however.

 

Won't be able to use this.

 

 

Trying to find a impero replacement. The power management is a bit broken for some reason as it tries to shut down computers not in the group.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...