Open
Close

Shutting down the computer via the command line. Shut down the computer from the command line Windows 7 shutdown command

Most users turn off their computer using the button located in the Start menu. Some people use physical power buttons on their machines. Very few people use the method by which it is possible shut down computer from command line.

The reason for this is that most of us don't know that you can use the command line not only to shut down or log off, but also to shut down a remote computer if you have administrative access. With these privileges, you can send a message containing the reason for the shutdown. This post will show you how to do it.

Your first action will be... At the initial stage, do this using one of several methods:

  1. Press the Windows key (window icon) + R.
  2. In the Run window, type CMD and press OK with your mouse or Enter on your keyboard.

This will launch the command prompt. Follow the instructions below depending on what you want to do.

Shutting down the local computer (yours)

Here you will need one single shutdown command, but if you enter it in this form, you will not succeed. The command uses its extensions, namely the S prefix, which indicates that the device is disabled.

Enter shutdown -s at the command prompt and press Enter, which will soon cause the PC to temporarily shut down with a warning. If you use shutdown -p, the computer will turn off instantly.

The peculiarity of shutdown is that the computer can be shutdown from command line after a certain amount of time. The command above is prefixed with t, a numeric variable, and becomes shutdown –s -t 300.

Once executed, a countdown timer starts and a warning message is displayed. The numeric variable (in this case 300) represents the number of seconds after which the computer will shut down. Set your number of seconds based on your needs.

To display a message containing the reason for shutdown, use shutdown –s -t 500 -c "I'm tired. I don't want to work, I'm going home"(with quotes) in cmd and press Enter key. The -c option is used in the command to comment out the reason for the shutdown and what follows in quotes will be displayed in the dialog box as an explanation. This can be used to display funny messages.

Shutting down a remote computer

To turn off the remote computer Type shutdown -s -m \\computer name in cmd and press Enter. Replace "\\computer name" with the actual name of the remote PC to attempt shutdown. As mentioned earlier, you must have administrator access to the computer you are trying to shut down. To find out if you have administrative access rights, press the Windows + R key combination, enter the computer name, then press the Enter key.

Note: If you don't remember the name of the remote computer, you can find it by opening a list of all connected PCs by running net view on the command line.


If you can connect to your computer, you will need to enter your username and password. Once you enter them, the window will display a list of all directories available to you. This should help you know whether you can or cannot shut down the remote computer.

Use an expression like "shutdown -a" to roll back a shutdown. This will stop the system shutdown, shutting down if the countdown has not reached 0.

That's all, I hope the lesson was useful and you already know how to shut down computer from command line. You should always remember that running as an administrator gives you privileges, and everything else is not too difficult to figure out!

Sometimes, while using a computer, situations arise when you need to turn off the computer through the command line.

Using shutdown

It’s worth saying right away that the set of shutdown commands is quite wide and allows you not only to quickly turn off the computer, but also to reboot it, turn it off after a certain time, and perform other actions.

There is also a force shutdown command in case everything else still refuses to work and the computer is still on.

Running the command line

To use shutdown, you need to launch Command Prompt.

To do this, go to the Start menu or the Windows menu in later versions, then open All Programs, Accessories section and click on Command Prompt.

The second way is to launch the program execution window by simultaneously pressing the Win and R buttons on the keyboard and enter the cmd.exe command there.

After this, all you have to do is press Enter on the keyboard or just press OK in the same window. Both of these methods can be seen in Figure 1.

Entering instructions

  • s – turn off the computer;
  • r – restart the computer;
  • a – stop turning off the computer;
  • f – force shutdown the computer.

That is, the command to simply turn off the computer will look like this:

shutdown -s

Entering this command looks as shown in Figure 2.

Special Instructions

In addition to all of the above, the shutdown command has a set of special instructions. They look like this:

  • i– displaying help about this set of commands;
  • l– exit this menu;
  • m\\– action with a remote computer;
  • t[time after which the computer will be turned off] – shutdown after a certain period of time;
  • d– computer shutdown reason code.

The last command is entered with custom code parameters ( u), scheduled completion code ( p), main reason code ( xx) and additional code ( yy) in this format:

[u][p]:xx:yy

As for the remote computer control command, an example of its input will look something like this: if we are talking about entering an IP address -

shutdown –m \\192.168.1.1 ;

if the computer is connected by and its name is known –

shutdown –m \\komp1 .

The shutdown command after a certain period of time is entered something like this:

shutdown –t 25 .

This means that the computer will turn off after 25 seconds. A description of all these commands can be seen if you call up help, what is done by the command

shutdown -i .

You can enter a whole set of commands on the same line at once.

For example, to turn off a computer with IP address 192.165.3.4 after 45 seconds, you must enter the following:

shutdown –s –t 45 –m \\192.165.3.4.

Figure 3 visualizes what entering these instructions looks like.

These commands can be entered not through a dash (-), but also through a slash (/). In this case, everything will look like this.

Another option for entering commands

All of the above commands can be entered not only into the command line, but also into the program execution window.

Above are instructions on how to launch the command line through it, but this is not at all necessary.

The shutdown command, along with all other instructions, can also be entered into the program execution window.

To launch it, as before, you need to simultaneously press the Win and R buttons on the keyboard. And then you can enter exactly the same commands that were listed above.

For example, entering a command to force a shutdown will look like this.

You can also enter more complex instructions here, an example of which was given above.

This input option has some advantages.

For example, in the command line, the user will not see the shutdown process occurring after a certain period of time - it will simply pass and the machine will turn off.

But if you enter a command to shut down the work after, for example, 60 seconds, a window with a timer will appear on the screen, which will start at 60 seconds and will go down until it reaches 0 (zero) seconds and turns off.

An example of such a window is shown in Figure 6.

In addition, the program execution window will automatically display the commands that the user entered previously.

By simply hovering over one of them, you can enter it again. It all looks something like what is shown in Figure 7.

It is important to understand that it is impossible to interrupt the shutdown instructions by simply closing such a window.

As mentioned above, there is a special command for this: s hutdown. Only she can stop the shutdown.

Therefore, if you have already entered one of the instructions along with the word shutdown, and then changed your mind, urgently open the command line or program execution window and enter shutdown -a.

A visual use of shutdown-related instructions is shown in the video below.

Operating system developer Windows Scheduled options are available. As such, there is no shutdown button indicating parameters. To do this, you need to use the command line and other standard (built-in) tools Windows. This method is especially good because it works always and everywhere, since it was developed and provided directly by the operating system developer himself. Tested on Windows XP, Windows 7, Windows 8.1

Those who are not interested in theory can go straight to the sections:
-
-

Shut down or restart your computer on a schedule
(at a specified time) with standard (built-in) Windows tools

Scheduled
(at a specified time) from the command line (MS DOS)

Since time immemorial, all operating systems in the MS Windows family have included a disk operating system (abbreviated as MS DOS), which does not have a familiar user interface for clicking on it with the mouse. MS DOS is controlled by entering a set of text commands using the keyboard in a special window, in the so-called command line . The command line works on any computer running any modification of the MS Windows operating system.

In the operating system MS Windows, from the command line you can do absolutely everything that this system is capable of.

TO command line can be called in one of the following ways:

  • press a key combination Win+R, enter cmd.exe, click OK
  • “Start Menu > Run”, enter cmd.exe, click OK
  • “Start Menu > All Programs > Accessories > Command Prompt”

Either way, a window will open MS DOS
(command line to enter a text command)
It is in it (on the command line) that we will:

  1. turn countdown on and off
    shutting down or restarting the computer
    (i.e. indicate after how long to perform the action)
  2. assign and cancel exact FOR
    shutting down or restarting the computer
    (i.e. indicate exactly when to perform an action)

All manipulations come down to accessing the file shutdown.exe
and specifying the required parameters

shutdown command options and syntax
(to access the shutdown.exe file)

File shutdown.exe is responsible for shutting down the operating system Windows, rebooting it, etc. To get a list of file launch parameters shutdown.exe from the command line - press the keyboard shortcut Win+R, in the window that opens, enter cmd.exe(go to MS DOS) and already in the DOS window (manually) enter “ shutdown/?"(without quotes). Click "OK" ("Enter" key). In response, the system will display a complete list of command parameters shutdown:

Regarding the parameter syntax for the command shutdown, That MS DOS understands both recording options - and with a hyphen (minus sign " - " on the numeric keypad) and through a slash (slash on the numeric keypad):

  1. shutdown /s /f /t 2000 equivalent shutdown -s -f -t 2000
  2. at 23:15 shutdown /r /f equivalent at 23:15 shutdown -r -f

In our case, there is no fundamental difference between a slash and a hyphen. It is much more important to remember about spacing. Because, in the understanding of the operating system, slash equals hyphen followed by space , then without a space - it may not work.

For example, in the screenshot above, I entered the commands “ shutdown-?" And " shutdown -?", and " shutdown/?" And " shutdown/?" The system's answer is obvious.

Simplified entry of the shutdown command
(Run window)

To turn the countdown timer on or off, open the “Run” window ( Win+R OK.

The time before turning off (rebooting) the computer must be entered in seconds.

Correct command entry is confirmed by corresponding pop-up windows in the tray. Pop-ups should appear after each correct command entry. They look something like this:

System response to a command to turn off or restart the computer after 33 minutes = 2000 seconds
System response to a command to cancel a command to shut down or restart the computer

10 minutes before the task is completed, the system begins to remind you that the countdown is about to end. The reminder form can have several options. Probably depends on the version of Windows and the design style.

A few minutes before the task is completed, the system notifies that the countdown is about to end.

Command line installation
exact time of the current date
to shut down and restart the computer

Setting the exact time of the current date from allows you to set the exact time of the current date to shut down or restart the computer. This task will only be executed ONCE, after which the task assignment procedure will need to be repeated. If you need the computer to be systematically turned off according to a schedule (at the same time), then you need to use or

To set the exact time of the current date to shut down or restart the computer, open the “Run” window ( Win+R), enter the desired command and click OK.

The computer shutdown (reboot) time must be entered in the specified format.
Time values, of course, are different for everyone.

Unlike installation, correct command entry when setting the time to shut down or restart the computer is not confirmed by the corresponding pop-up windows in the tray

It is convenient to create from the command line DISPOSABLE task to shut down or restart the computer. If you need to systematically turn off the computer on a schedule (for example, at a given time, at the end of the working day), then you need to set the shutdown time after or after

Shutdown and restart your computer
using an executive (batch) file

Executive (batch) files with the extension .bat() make working with the command line much easier. Once you have created such a bat file with the text of the required command, you can execute it by simply clicking on the batch file, without tediously calling the command line window and entering the command text into it.

Let's remember the list of our commands and create the corresponding batch files:

  1. shutdown /s /f /t 2000 or shutdown -s -f -t 2000
    (turn off computer after 33min = 2000 seconds)
  2. shutdown /r /f /t 2000 or shutdown -r -f -t 2000
    (restart computer after 33min = 2000 seconds)
  3. at 23:15 shutdown /s /f or at 23:15 shutdown -s -f
    (turn off the computer today at 23:15)
  4. at 23:15 shutdown /r /f or at 23:15 shutdown -r -f
    (reboot your computer today at 11:15 pm)
  5. shutdown/a or shutdown -a
    (cancel the command to shutdown/restart the computer)

To create an executive (batch) batch file, open notepad, copy (write) the required command line into it and save the file with the .bat extension. For example, let's create two files - the “Shutdown.bat” file and the “Cancel.bat” file. In the first file we write the line “ shutdown /s /f /t 2000" (without quotes), in the second - the line " shutdown/a"(without quotes). Clicking on the first file will give a command to turn off the computer after 33 minutes = 2000 seconds. Clicking on the second file will cancel the command to turn off the computer after 33 minutes = 2000 seconds. Thus, we will receive two files, clicking on which will have the same effect as in the case of a call and entering the desired command into it.

Everything is very simple, and it is much more convenient than the command line. In addition, this method gives room for flight of imagination and creative thought. For example, you can set the timeout to 28800 seconds. (28800 seconds = 8 hours = length of a working day), put the “Shutdown.bat” file in the computer’s startup folder and no longer worry about turning it off at the end of the working day. Because every time the system boots, it will receive a command to shut down after 8 hours = 28800 seconds. The same effect will be achieved by the executable.bat file in startup, with the content “ at 17:00 shutdown /s /f"(without quotes). Moreover, this command is even preferable, since it sets the exact time to turn off the computer and does not depend on the number of reboots during the working day.

Funny. If you set the timeout to 180 seconds in the bat file in the startup folder, then the computer will turn off 3 minutes after it starts.

Shutdown and restart your computer
at a specified time via the task scheduler

The task scheduler is a special feature Windows. The Task Scheduler allows you to create and execute various scheduled tasks. In our case, this means systematically turning off or restarting the computer at a specified time. Unlike and, the task scheduler allows you to more flexibly assign the exact time and frequency of shutting down the computer.

To configure the computer to shut down or restart at a specified time through the task scheduler, open the task scheduler. It is located in “Start Menu > All Programs > Accessories > System Tools > Task Scheduler”

Then, in the window that opens, write the name of the task and its description. Here you can write whatever you want. The task name and description will then be displayed in the middle column of the scheduler after the task is created. I wrote the name - “Shutdown”, the description - “Turn off the computer” and clicked the “Next” button...

In the next window that opens, you need to select the frequency of the task. I chose “Daily”. "Further"...

In the next window that opens, you need to specify the date from which to start executing the task and the time it will be completed. By default, the current date and time are displayed. The date can be left unchanged (start today), but you need to set your own time. This will be the required time to shut down the computer. I set it to 17:00:00, which corresponds to the end of my working day. The line “Repeat every 1 day.” - left unchanged. "Further"...

In the next window that opens, you need to set the switch (checkbox) next to the words “Run the program”. "Further"...

In the next window that opens, in the “program or script” line, enter the command “ shutdown" (without quotes), and in the "add arguments" field " -s -f" (without quotes) - to turn off. If you need to restart the computer, then in the “add arguments” field enter “ -r -f"(without quotes). "Further"...

Click the “Done” button. Problem on daily computer shutdown at 17:00- created and launched. You can check your work or delete a task as follows. We launch the scheduler, click on “Task Scheduler Library” and in the middle column we find the desired task (by name). Right-click on it and select the one you need from the drop-down menu.

To check, I clicked on “Run”. The computer responded instantly. It works, hurray!

Turning off the computer
Shut down your computer from the command line

Most users are accustomed to shutting down their computer using the Start menu. Even if they heard about the possibility of doing this via the command line, they never tried to use it. All this is due to the preconception that it is something very complex, intended exclusively for computer professionals. Meanwhile, using the command line is very convenient and provides the user with many additional options.

To shut down a computer using the command line, the user needs to know two fundamental things:

  • How to open the command line;
  • What command to turn off the computer.

Let's look at these points in more detail.

Call the command line

Calling the command line, or the console as it is also called, is very simple in Windows. This is done in two steps:


The result of these actions will be the opening of a console window. It looks approximately the same for all versions of Windows.


You can call the console in Windows in other ways, but they are all more complex and may differ in different versions of the operating system. The method described above is the simplest and most universal.

Option 1: Shut down the local computer

To shut down the computer from the command line, use the shutdown command. But if you simply type it into the console, the computer will not turn off. Instead, help will be displayed on how to use the command.


After carefully studying the help, the user will understand that to turn off the computer you need to use the command shutdown with parameter [s]. The line typed in the console should look like this:

shutdown /s

After entering it, press the key Enter and the system shutdown process will begin.

Option 2: Using a timer

By entering the command in the console shutdown /s, the user will see that the computer shutdown has not yet started, but instead a warning appears on the screen that the computer will be turned off in a minute. This is what it looks like on Windows 10:


This is because this time delay is provided by default in this command.

For cases when the computer needs to be turned off immediately, or at another time interval, in the command shutdown parameter provided [t]. After entering this parameter, you must also specify the time interval in seconds. If you need to shut down the computer immediately, its value is set to zero.

shutdown /s /t 0

In this example, the computer will turn off after 5 minutes.


A system termination message will be displayed on the screen in the same way as when using a command without a timer.


This message will repeat periodically indicating the remaining time until the computer shuts down.

Option 3: Shutdown the remote computer

One of the advantages of shutting down a computer using the command line is that this way you can shut down not only the local computer, but also the remote computer. For this purpose in the team shutdown parameter provided [m].

When using this parameter, it is mandatory to specify the network name of the remote computer, or its IP address. The command format looks like this:

shutdown /s /m\\192.168.1.5

As with the local computer, you can use a timer to shut down the remote machine. To do this, you need to add the appropriate parameter to the command. In the example below, the remote computer will be turned off after 5 minutes.

To turn off a computer located on the network, it must have remote control enabled, and the user who will perform this action must have administrator rights.

35,421 Views

I had a task to organize the rapid shutdown of remote servers in one click. Moreover, various users must turn off servers, including those without knowledge and understanding of the principles of server operation. That is, they just have to press a button to have the server shut down automatically.

Moreover, you need to turn off both Windows servers and Linux servers of various distributions over the network - ubuntu, centos, freebsd. That is, the solution must be simple and reliable.

Remote shutdown of Windows server

Let's start with the most difficult one. In practice, implementing a reliable way to turn off Windows machines over the network turned out to be more difficult for me than Linux. There are many methods and approaches to solving this problem. I tried different options and settled on one that seemed the most reliable, it worked without problems in all cases during testing.

A prerequisite for remotely shutting down a server is network access to it via rdp. You can be on the local network with it, or forward the rdp connection by redirecting from the gateway. It doesn’t matter, the main thing is to get into the system via rdp.

The operating principle of remote shutdown is as follows:

  1. A user is created on the computer or server who will be allowed to connect via rdp and shut down the server.
  2. This user's startup will contain a shutdown script.
  3. Users who will shut down the server remotely are given a specially prepared rdp client, which, without any requests, will be connected by the desired user, for whom the shutdown script will be triggered.

Everything is quite simple, but at every stage I encountered problems that required a non-trivial solution. But first things first.

So, let's go north and create a simple bat file there with the following content:

Shutdown /p /d p:0:0 /f

We save the file and create a user under which we will shut down the server. Don't forget to add permission for this user to connect via rdp. If you turn off a computer with a desktop system, then the rights of a regular user are sufficient. If you need to turn off Windows Server, then you need to either make the user an administrator or give him the rights to allow him to turn off the server through the local security policy. This politician lives at the address - security settings - local policies - assigning user rights - shutting down the system.

This is where I ran into my first troubles. I named my script shutdown.bat and for a very long time I could not understand why it did not work. When entering the command shutdown everything worked fine with the parameters in the console, but the script did not run. It turns out that he cannot be called by that name. After I renamed it to shut.bat, everything worked fine. It's kind of a ridiculous snag, but I had to spend a lot of time before I figured out what it was all about.

Next, we go to our new user so that standard profile folders are created and put the server auto-shutdown script in his startup - C:\Users\shut-user\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup.

Now we need to configure automatic user login via rdp to perform remote shutdown. Moreover, the user must log into the server without asking for a name and password. This cannot be done using standard Windows rdp client tools. Even if you save the settings, you will need to enter the password again when you transfer the settings to another computer. It didn't suit me.

I tried using an old ported version of rdp 5.2. This is the last version where the password could be stored encrypted in the settings file. But when I transferred this file to another computer, a password entry window still popped up. It was not possible to achieve complete automation.

But a solution was found. There is an interesting project called Remote Desktop Plus, which is an add-on to rdp. Using this add-on, you can pass parameters to rdp via the command line, including the username and password. This suits me completely. Download the file either from the project author’s website or from mine. I copied this very useful utility just in case. We put it in a folder and create it in the same folder rem-shut.bat file with the following content:

Rdp.exe /v:10.10.5.14 /u:shut-user /p:pass123 /w:640 /h:480

All this is enough to perform a remote shutdown on a Windows server. The user needs to transfer 2 files:

  • rdp.exe
  • rem-shut.bat

It is important that they are in the same folder. When you run the batch file, the user's rdp will be connected and the shutdown script will be executed. Mission accomplished.

Remote shutdown of Linux server

Here everything turned out to be much simpler. A working solution was immediately found that allows you to remotely shut down any Linux server without any problems. The problem is solved using standard putty tools. This program can be run from the command line with parameters. As parameters, you can specify a file with commands to execute, server address, user and password.

We will prepare everything you need. First, create a simple text document shutdown.txt the following content:

Putty.exe -m shutdown.txt -ssh -P 22 -l root -pw rootpass 10.10.5.15

We transfer 3 files to the user, placed in one folder:

  • putty.exe
  • shutdown.txt
  • serv-rem-shut.bat

Now, when you run the serv-rem-shut.bat script, a console command will be sent to the server over the network to shut down. No questions will be asked. The server will simply shut down silently.

Conclusion

These are the simple methods I came up with and implemented. It is also important to provide access to the local network in which the servers live. In my case, openvpn allows you to remotely shut down computers even over the Internet.

I'm sure there are many other options to extinguish the server remotely. I would be glad if someone would share their ideas and experiences on this matter with me in the comments.

Online course on Linux

If you have a desire to learn how to build and maintain highly available and reliable systems, I recommend that you get acquainted with online course “Linux Administrator” in OTUS. The course is not for beginners; for admission you need basic knowledge of networks and installing Linux on a virtual machine. The training lasts 5 months, after which successful course graduates will be able to undergo interviews with partners. What this course will give you:
  • Knowledge of Linux architecture.
  • Mastering modern methods and tools for data analysis and processing.
  • Ability to select a configuration for the required tasks, manage processes and ensure system security.
  • Proficient in the basic working tools of a system administrator.
  • Understanding of the specifics of deploying, configuring and maintaining networks built on Linux.
  • The ability to quickly solve emerging problems and ensure stable and uninterrupted operation of the system.
Test yourself on the entrance test and see the program for more details.