从 linux 终端关闭 Windows 机器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9936986/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 05:30:22  来源:igfitidea点击:

Shutdown Windows machine from linux terminal

windowslinuxshutdown

提问by ganesshkumar

I am running an application on linux machine. By giving the ip address of a windows machine as input, the application must shutdown the windows machine. If the machines run the same OS it is very easy but I'm confused how to do it in cross OS.

我正在 linux 机器上运行一个应用程序。通过提供 Windows 机器的 ip 地址作为输入,应用程序必须关闭 Windows 机器。如果机器运行相同的操作系统,这很容易,但我很困惑如何在跨操作系统中做到这一点。

采纳答案by ganesshkumar

Command to shutdown windows system from linux -:

从 linux 关闭 windows 系统的命令 -:

$ net rpc -S <ip address> -U <username>%<password> shutdown -t 1 -f

$ net rpc -S <ip address> -U <username>%<password> shutdown -t 1 -f

This command can be issued from bash or even set in cron job to shutdown the computer at a specific time and this command is shipped with many distros by default.

此命令可以从 bash 发出,甚至可以在 cron 作业中设置以在特定时间关闭计算机,默认情况下,此命令随许多发行版一起提供。

回答by Jayan

Option 1: Install SSH server on windows. Login to this server from any box and call shutdown command. We use Interix(Microsoft's unix like environment). It comes with a telnet server- allows to invoke windows commands from other machines..

选项 1:在 Windows 上安装 SSH 服务器。从任何盒子登录到此服务器并调用关闭命令。我们使用 Interix(微软的类 unix 环境)。它带有一个 telnet 服务器 - 允许从其他机器调用 Windows 命令..

Another option: If you samba installed on windows it can connect to windows and call windows commands

另一种选择:如果您在 windows 上安装了 samba,它可以连接到 windows 并调用 windows 命令

 net rpc SHUTDOWN ...

(from http://www.linuxforums.org/forum/red-hat-fedora-linux/60324-remote-shutdown-windows-linux-box.html#post573872)

(来自http://www.linuxforums.org/forum/red-hat-fedora-linux/60324-remote-shutdown-windows-linux-box.html#post573872

Another option: try rdesktop to the windows machine with shutdown command ( I use it for running windows batch script which has shutdown in it, not sure if you can directly call shutodwn)

另一种选择:使用shutdown命令尝试rdesktop到windows机器(我用它来运行windows批处理脚本,里面有shutdown,不确定是否可以直接调用shutodwn)

回答by Ernest Friedman-Hill

It depends on your infrastructure -- how you authenticate to the Windows machines, whether you can configure them yourself, etc. If it were me, I'd put Cygwinon the Windows boxes, then sshto them and run shutdown -h. There are surely other ways to do it, of course.

这取决于你的基础设施——你如何对 Windows 机器进行身份验证,你是否可以自己配置它们等等。如果是我,我会把Cygwin放在 Windows 机器上,然后ssh对它们运行shutdown -h. 当然,肯定还有其他方法可以做到。

回答by ghoti

You need a way to launch a shell on the Windows box so you can run th shutdowncommand built in to Windows.

您需要一种在 Windows 机器上启动 shell 的方法,以便您可以运行Windows 内置的关机命令。

You can install Cygwinfor this, then install an SSH daemon in Windows. Once that's running, your Linux box can run commands on the Windows box just as if it were another Linux machine.

您可以为此安装Cygwin,然后在 Windows 中安装 SSH 守护程序。一旦运行,您的 Linux 机器就可以在 Windows 机器上运行命令,就像它是另一台 Linux 机器一样。

Here are some instructions for setting up Cygwin's sshd in Windows.

以下是在 Windows 中设置 Cygwin 的 sshd 的一些说明

回答by Nirmal- thInk beYond

Use telnetcommand in Linux, make sure telnet is enabled in Windows system

在 中使用telnet命令Linux,确保telnet is enabled in Windows system

回答by nouknouk

There may be more setup to do, especially for Windows Vista, Windows 7 and further windows versions, to allow remote shutdown:

可能需要进行更多设置,特别是对于 Windows Vista、Windows 7 和更多 Windows 版本,以允许远程关机:

Part A) On the Windows machine:

A 部分)在 Windows 机器上:

1) Add a remote shutdown security policy:

1) 添加远程关机安全策略:

  • run secpol.msc

  • in the program tree, open Security Settings> Local Policies> User rights Assignment

  • Find the entry Force shutdown from a remote system

  • Edit the entry, add the windows user account that will be used for shutdown (ex: nouknouk)

  • secpol.msc

  • 在程序树,开Security Settings> Local Policies>User rights Assignment

  • 查找条目 Force shutdown from a remote system

  • 编辑条目,添加将用于关机的 Windows 用户帐户(例如:nouknouk)

2) Add registry keys to disable UAC remote restrictions:

2) 添加注册表项以禁用 UAC 远程限制:

  • Run regedit.exeas Administrator

  • Find HKLM/SOFTWARE/Microsoft/Windows/CurrentVersion/Policies/System

  • Create a new registry DWORD(32)value named LocalAccountTokenFilterPolicyand then assign it the value 1

  • regedit.exe以管理员身份运行

  • HKLM/SOFTWARE/Microsoft/Windows/CurrentVersion/Policies/System

  • 创建一个DWORD(32)名为的新注册表值LocalAccountTokenFilterPolicy,然后为其分配值1

3) Start remote registry service:

3) 启动远程注册服务:

  • Open cmd.exeas Administrator

  • Execute the two following commands:

    sc config RemoteRegistry start= auto

    sc start RemoteRegistry

  • cmd.exe以管理员身份打开

  • 执行以下两条命令:

    sc config RemoteRegistry start= auto

    sc start RemoteRegistry

Part B) On the Linux machine:

B 部分)在 Linux 机器上:

1) install the package samba-common:

1)安装包samba-common

It depends on your Linux distribution, but for Debian and derivated (Ubuntu, Linux Mint, ...), the apt-get command can be executed like that:

这取决于您的 Linux 发行版,但对于 Debian 和衍生版本(Ubuntu、Linux Mint 等),可以像这样执行 apt-get 命令:

apt-get install samba-common

apt-get install samba-common

2) To actually shutdown your Windows machine from the Linux one, run the following command:

2) 要从 Linux 中实际关闭您的 Windows 机器,请运行以下命令:

net rpc shutdown -f -t 0 -C 'message' -U userName%password -I xxx.yyy.zzz.ttt

net rpc shutdown -f -t 0 -C 'message' -U userName%password -I xxx.yyy.zzz.ttt

Where:

在哪里:

  • -fmeans force shutting down all applications (may be mandatory)

  • -t 0is the delay before doing it (0 means 'right now').

  • -U user%passwordis the local user and his password on the windows machine (the one that has been allowed to do remote shutdown in part A).

  • -Iis the IP address of the windows machine to shutdown.

  • -f意味着强制关闭所有应用程序(可能是强制性的)

  • -t 0是做之前的延迟(0 表示“现在”)。

  • -U user%password是 Windows 机器上的本地用户和他的密码(在 A 部分中允许远程关机的那个)。

  • -I是要关闭的 Windows 机器的 IP 地址。

回答by PCatinean

It's important to note that the above solution will not work if the username in question does not have a password set (at least that's how it was in my case).

重要的是要注意,如果有问题的用户名没有设置密码,则上述解决方案将不起作用(至少在我的情况下是这样)。

For windows 10 (and below maybe, did not check) users one must go to the firewall settings and enable "Remote Service Management" for the linux box to be able to connect via rpc.

对于 Windows 10(可能和更低版本,没有检查)用户,必须转到防火墙设置并启用“远程服务管理”以使 linux 框能够通过 rpc 连接。

回答by Benoit C.

To find your actual Windows username, open cmd and run

要查找您的实际 Windows 用户名,请打开 cmd 并运行

echo %username%

This is the username (not case sensitive) you have to use in your net rpc command

这是您必须在 net rpc 命令中使用的用户名(不区分大小写)