本文将向您展示如何使用Windows中的远程关闭命令工具(command tool)远程关闭或重新启动本地或联网计算机。如果您在家中或网络上有多台计算机要快速关闭或重新启动,这有时会非常有用。
您甚至可以通过Internet远程关闭计算机,但您首先必须通过VPN连接到网络或要关闭的目标计算机。(target computer)我不会在本文中介绍VPN(VPNs),但如果这是您想做的事情,请随时在 Google 上搜索。
您可以使用shutdown 命令及其相关开关从命令提示符、远程关机(command prompt)对话框(dialog box)或批处理文件(batch file)执行远程关机。我将在本文中介绍所有三种方法。
远程关机概述
为了使其正常工作,您必须首先完成几个步骤,否则您将不断收到拒绝访问 (5)(Access is Denied (5)) 错误消息(error message),它会让您发疯。
第 1 步(Step 1):首先,为了远程关闭网络上的计算机,您需要确保您对目标计算机具有管理访问权限。如果您在家庭网络(home network)上,最好的方法是确保所有计算机都在同一个工作组中,并且它们都至少有一个具有相同用户名和密码的(username and password)管理员帐户(Administrator account)。
您不必使用任何一台计算机上的内置管理员帐户(administrator account)来进行此操作,但您在两台计算机上使用的用户帐户(user account)必须是本地计算机上管理员组的一部分。(Administrators group)如果您转到控制面板并单击(Control Panel and click)用户帐户(User Accounts)并显示Administrator或Local Administrator,那么您就可以了。同样(Again),用户帐户的名称和密码必须相同。
如果您在具有域的公司环境中,您可能希望使用域管理员帐户(domain administrator account)登录。使用这些凭据,您应该能够关闭网络上的任何其他计算机,即使它们使用不同的凭据登录。
第 2 步(Step 2):第二步是打开文件和打印机共享(File and Printer Sharing)并允许它通过Windows 防火墙(Windows firewall)。为此,请转到控制面板并首先单击(Control Panel and click)网络和共享中心(Network and Sharing Center)。单击左侧菜单中的(left menu)更改高级共享设置(Change advanced sharing settings)链接,然后选择打开网络发现( Turn on network discovery)和打开文件和打印机共享(Turn on file and printer sharing)单选按钮(radio button)。
返回主控制面板窗口并单击(Control Panel window and click)Windows防火墙(Windows Firewall)。单击(Click)左侧菜单中的允许程序或功能通过 Windows 防火墙(Allow a program or feature through Windows Firewall)。
确保您只选中Home/Work (Private)框而不是Public。您不需要允许其他任何东西通过防火墙。您可能会在其他网站上阅读以允许WMI、Remote Shutdown、Network Discovery等,但我已经在没有任何这些的情况下对其进行了测试,它工作得很好。
第 3 步(Step 3):最后,如果您尝试远程定位Windows Vista、Windows 7 或 Windows 8 计算机,则需要修改注册表。除非你这样做,否则它根本行不通。无论如何,您只会收到拒绝(Denied message)访问消息。(Access)
通过转到开始并输入(Start and typing)regedit打开注册表编辑(registry editor)器。现在导航到以下键:
HKEY_LOCAL_MACHINE – SOFTWARE – Microsoft – Windows – CurrentVersion – Policies – System
右键单击左侧的System并选择(System)New – DWORD (32-bit) Value。
右侧窗口(right window)底部会弹出一个新值,文本将突出显示。将名称更改为 LocalAccountTokenFilterPolicy并按Enter。现在双击它并将值从 0 更改为1。
单击确定(Click OK)并关闭注册表。您无需重新启动计算机,因为更改会立即生效。需要此注册表项(registry key),因为在Windows Vista和更高版本中,管理员帐户(administrator account)在远程连接时会被剥夺其凭据。这将允许该帐户保留管理权限。
您还将在其他站点上阅读以启动远程注册表(Remote Registry)服务(如果该服务未运行),并通过将“所有人”(Everyone)组添加到从远程系统策略设置强制关闭来编辑本地( Force shutdown from a remote system)安全策略。(security policy)在我对Windows 7和 8 的测试中,没有必要完成这些任务,你真的不应该这样做,因为它会将你的系统向潜在的黑客开放。
显然,您还需要知道网络上其他计算机的所有名称。您可以通过转到控制面板(Control Panel)然后单击系统(System)来做到这一点。
通过命令提示符远程关机
关闭命令在命令提示符下(command prompt)使用时最为灵活,因为您可以向其添加一堆开关,从而允许您自定义行为。转到Start,然后Run,然后输入CMD。您可以通过键入 shutdown /? 来查看开关列表。在命令窗口(command window)中。
您必须至少使用一个开关才能让命令执行任何操作。基本上(Basically)你会输入shutdown /x /y /z 其中 x, y, z 是上面列表中的字母。
以下是一些最常见的命令开关及其执行的操作:
/s:关闭计算机
/r:重新启动计算机
/m \\computername : 要关闭的目标远程计算机
/f:强制程序立即关闭
/t: 在关闭或重新启动之前将等待一定的时间(以秒为单位)
/a:如果您将先前的关机命令与 /t 一起使用,则中止关机。
因此,要远程关闭网络上的另一台机器,您可以在命令提示符中键入以下命令:
shutdown /m \\computername /r /f
此命令将重新启动名为computername的计算机并强制关闭所有仍在运行的程序。
shutdown –m \\computername –s –f –c “The computer will restart, please save all work.” –t 60
此命令将关闭名为computername的计算机,强制关闭所有正在运行的程序,向用户显示一条消息并在关闭前 60 秒倒计时。
通过关机对话框远程关机
如果您不喜欢所有这些开关或一般不使用命令提示符(command prompt),那么您可以打开关机对话框(dialog box)。/i command switch用于关闭命令,您就可以轻松做到这一点。
现在将出现远程关机对话框,如下所示。
单击添加(Add)或浏览(Browse)按钮将计算机添加到列表中。然后,您可以在整批计算机上运行这些命令。如果您单击Add,您需要以\\computername 或只是computername格式输入计算机的网络名称(network name),两者都可以。
当然,您需要知道实际的计算机名称(computer name),我在上面提到了如何确定。因此,将任意数量的计算机添加到列表中,然后设置您的选项。您可以关闭、重新启动或注释意外关闭。
如果愿意,您还可以显示警告,无论您选择多少秒,您都可以在底部输入一条评论,该评论将显示给用户。就是这样!
通过批处理文件远程关机
最后,您可以创建一个批处理文件(batch file),以便只需运行该文件即可完成所有这些工作。或者,您可以使用Task Scheduler安排(Task Scheduler)批处理文件(batch file)在特定时间间隔或在特定事件期间运行。
只需转到记事本并输入(Notepad and type)您在命令提示符(command prompt)中输入的命令:
shutdown –m \\computername1 –r
shutdown –m \\computername2 –r
shutdown –m \\computername3 –r
然后只需将文件保存为.BAT 文件扩展名(.BAT file extension),方法是选择“所有文件(All Files)”作为“保存类型 ( Save as type )”并将 .bat 添加到文件名(file name)的末尾。
这将重新启动我家庭网络(home network)上的三台计算机。您可以根据需要将任意数量的命令放入批处理文件(batch file)中,所以请随意尝试!
我写了一篇关于如何在 Windows 中使用批处理文件的详细(how to use batch files in Windows)文章,如果您不熟悉批处理文件或任务调度程序(task scheduler),请阅读这篇文章。享受!
How to Remotely Shutdown or Restart a Windows Computer
This article will show you how to use the remote shutdown command tool in Windows to remotely shutdown or restart а local or networked computer. Thiѕ can be very useful sometimes if you havе multiple computers аt home or on your network that you want to quickly shutdown or restart.
You can even remotely shutdown a computer over the Internet, but you would first have to either VPN into the network or into the target computer you want to shut down. I’m not going to cover VPNs in this article, but if that’s something you want to do, feel free to Google it.
You can perform a remote shutdown from the command prompt using the shutdown command and its associated switches, from the remote shutdown dialog box, or from a batch file. I’ll go through all three methods in this article.
Remote Shutdown Overview
In order to get this to work, there are a couple of steps you have to complete first otherwise you’ll constantly get an Access is Denied (5) error message and it will drive you mad.
Step 1: Firstly, in order to remotely shutdown a computer on your network, you’ll need to make sure you have Administrative access to the target computer. If you’re on a home network, the best way to do this is to make sure all computers are in the same workgroup and that they all have at least one Administrator account with the same username and password.
You don’t have to use the built-in administrator account on either computer for this to work, but the user account you do use on both computers has to be part of the Administrators group on the local computer. If you go to Control Panel and click on User Accounts and it says Administrator or Local Administrator, then you’re fine. Again, the names of the user accounts and the password have to be the same.
If you’re in a corporate environment with a domain, you will probably want to login using the domain administrator account. Using those credentials, you should be able to shutdown any other computer on the network, even if they are logged in using different credentials.
Step 2: The second step is to turn on File and Printer Sharing and to allow it through the Windows firewall. To do this, go to Control Panel and click on Network and Sharing Center first. Click on the Change advanced sharing settings link in the left menu and select the radio button for Turn on network discovery and Turn on file and printer sharing.
Go back to the main Control Panel window and click on Windows Firewall. Click on the Allow a program or feature through Windows Firewall in the left menu.
Make sure you only check the Home/Work (Private) box and not Public. You do not need to allow anything else through the firewall. You might read on other sites to allow WMI, Remote Shutdown, Network Discovery, etc, but I’ve tested it without any of those and it works just fine.
Step 3: Lastly, if you are trying to target a Windows Vista, Windows 7 or Windows 8 computer remotely, you will need to modify the registry. Unless you do this, it simply won’t work. You will only get the Access is Denied message no matter what.
Open the registry editor by going to Start and typing in regedit. Now navigate to the following key:
HKEY_LOCAL_MACHINE – SOFTWARE – Microsoft – Windows – CurrentVersion – Policies – System
Right-click on System on the left hand side and choose New – DWORD (32-bit) Value.
A new value will pop up at the bottom in the right window and the text will be highlighted. Change the name to LocalAccountTokenFilterPolicy and press Enter. Now double-click on it and change the value from 0 to 1.
Click OK and close out of the registry. You don’t need to restart the computer as the changes should take effect immediately. This registry key is needed because in Windows Vista and higher, an administrator account is stripped of its credentials when connecting remotely. This will allow the account to remain with administrative privileges.
You’ll also read on other sites to start the Remote Registry service if that’s not running and to edit the local security policy by adding the Everyone group to Force shutdown from a remote system policy setting. In my testing on Windows 7 and 8, there was no need to complete these tasks and you really shouldn’t because it opens up your system to potential hackers.
Obviously, you’ll also need to know all the names of the other computers on the network. You can do that by going to Control Panel and then clicking on System.
Remote Shutdown via Command Prompt
The shutdown command is most flexible when using it from the command prompt because you can add a bunch of switches to it, which allow you to customize the behavior. Go to Start, then Run, and type in CMD. You can see the list of switches by typing shutdown /? in the command window.
You have to use at least one switch in order for the command to do anything. Basically you would type in shutdown /x /y /z where x, y, z are letters in the list above.
Here are a couple of the most common command switches and the actions they perform:
/s: Shuts down the computer
/r: Restarts the computer
/m \\computername: The target remote computer to shut down
/f: Forces programs to close immediately
/t: Will wait a certain amount of time in seconds before shutting down or restarting
/a: Aborts a shutdown if you used a previous shutdown command with /t.
So for remotely shutting down another machine on your network, you would type into the command prompt the following commands:
shutdown /m \\computername /r /f
This command will restart the computer named computername and force all programs that are still running to close.
shutdown –m \\computername –s –f –c “The computer will restart, please save all work.” –t 60
This command will shutdown the computer named computername, force all programs that are running to close, show a message to the user and countdown 60 seconds before it shuts down.
Remote Shutdown via Shutdown Dialog
If you don’t like all those switches or using the command prompt in general, then you can bring up the shutdown dialog box. You can do that easily by just using the /i command switch for the shutdown command.
The remote shutdown dialog will now appear as shown below.
Click the Add or Browse button to add computers to the list. You can then run the commands on the entire batch of computers. If you click Add, you’ll need to enter in the network name of the computer in the format \\computername or just computername, either works.
Of course, you need to know the actual computer name, which I mentioned how you can determine above. So add as many computers to the list as you like and then set your options. You can shutdown, restart or annotate unexpected shutdown.
You can also display a warning, if you like, for however many seconds you choose and you can type in a comment at the bottom which will be displayed to users. That’s about it!
Remote Shutdown via Batch File
Finally, you can create a batch file so that can do all of this by just running the file. Alternatively, you can schedule the batch file to be run at specific intervals or during specific events using Task Scheduler.
Just go to Notepad and type in the commands you would have typed into the command prompt:
shutdown –m \\computername1 –r
shutdown –m \\computername2 –r
shutdown –m \\computername3 –r
Then simply save the file with a .BAT file extension by choosing All Files for Save as type and add .bat to the end of the file name.
This will restart three computers on my home network. You can put as many commands into the batch file as you like, so feel free to experiment!
I’ve written an extensive post on how to use batch files in Windows, so read that if you are not familiar with batch files or task scheduler. Enjoy!