简体   繁体   中英

Batch Script to shutdown Windows

I need the following. A batch script that asks me if I want to shutdown windows 7 (Y/N).. If I click "Y", then Windows 7 shuts down right away.

Please help anyone.

You will be using SET to read an answer and set to a variable. if/goto statements carry it from there.

The shutdown command changed a bit since XP, but this is what I use for 7.

@echo off   
SET /P ANSWER=Did you even try Google (Y/N)?
echo You chose: %ANSWER%
if /i {%ANSWER%}=={y} (goto :yes)
if /i {%ANSWER%}=={yes} (goto :yes)
goto :no
:yes
echo You pressed yes!
shutdown /f /s /t 01 
:no
echo You pressed no!
shutdown
exit /b 1 

First link on Google for your search: https://answers.yahoo.com/question/index?qid=20081005123533AALLIPA

The most common ways to use the [ shutdown ][1] command are:

  • shutdown -s — Shuts down.

  • shutdown -r — Restarts.

  • shutdown -l — Logs off.

  • shutdown -h — Hibernates.

    Note: There is a common pitfall wherein users think -h means "help" (which it does for every other command-line program... except shutdown.exe , where it means "hibernate"). They then run shutdown -h and accidentally turn off their computers. Watch out for that.

  • shutdown -i — "Interactive mode". Instead of performing an action, it displays a GUI dialog.

  • shutdown -a — Aborts a previous shutdown command.

The commands above can be combined with these additional options:

  • -f — Forces programs to exit. Prevents the shutdown process from getting stuck.
  • -t <seconds> — Sets the time until shutdown. Use -t 0 to shutdown immediately.
  • -c <message> — Adds a shutdown message. The message will end up in the Event Log.
  • -y — Forces a "yes" answer to all shutdown queries.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM