从 Linux 机器重新启动 Windows 服务

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1195638/
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-09-15 12:52:58  来源:igfitidea点击:

Restarting a Windows service from a Linux box

windowswindows-services

提问by markdrayton

We have a crummy legacy Windows application (already discussed here) which replicates content to from a Windows host to many Linux hosts. We several instances of it running on several boxes. Each instance has its own .inifile containing a list destination servers. Fairly often we need to change the content of these files and restart the process, a process which is done by hand by our ops team. I'd like to replace this with a simple web-based utility (running on a Linux host) which allows users to generate the configuration files, send them to the hosts and restart the services. Generating the files is easy -- I'd probably use Perl and Template Toolkit -- and since the servers export their configuration directories copying the data is relatively easy as well.

我们有一个糟糕的遗留 Windows 应用程序(已经在这里讨论),它可以将内容从 Windows 主机复制到许多 Linux 主机。我们在几个盒子上运行它的几个实例。每个实例都有自己的.ini文件,其中包含一个目标服务器列表。我们经常需要更改这些文件的内容并重新启动该过程,该过程由我们的操作团队手动完成。我想用一个简单的基于 web 的实用程序(在 Linux 主机上运行)替换它,它允许用户生成配置文件,将它们发送到主机并重新启动服务。生成文件很容易——我可能会使用 Perl 和模板工具包——而且由于服务器导出它们的配置目录,复制数据也相对容易。

What're my options for restarting the Windows services? Win32::Service? I haven't had a chance to look very far yet so if you say "x::ymakes this easy, but watch out for z" you'd save me a lot of time. Is it even possible? Alternatively, perhaps you could suggest a better way to tackle this problem (replacing the software sadly is not one!) I'm not trying to be lazy, just avoid wasting time fiddling with modules that might not do what I want.

重新启动 Windows 服务有哪些选项?Win32::Service? 我还没有机会看得很远,所以如果你说“x::y让这很容易,但要注意 z”,你会为我节省很多时间。甚至有可能吗?或者,也许您可​​以提出一种更好的方法来解决这个问题(可悲的是更换软件不是一个!)我不是想偷懒,只是避免浪费时间摆弄可能无法满足我想要的模块。

回答by gimel

Ubuntu includes a utility that can help with managing Windows systems, wmic- WMI Client. With proper permissions, WMIcan easily stop and start Windows services.

Ubuntu 包含一个可以帮助管理 Windows 系统的实用程序wmic- WMI Client. 拥有适当的权限,WMI可以轻松停止和启动 Windows 服务。

(An example from the man page, not on service control.)

(来自手册页的示例,而不是关于服务控制的示例。)

EXAMPLE

wmic -U [domain/]adminuser%password //host "select * from Win32_ComputerSystem"

例子

wmic -U [domain/]adminuser%password //host "select * from Win32_ComputerSystem"

回答by Josh Kelley

Winexecan do this; it's the Linux equivalent to Sysinternal's very useful PsExectool.

Winexe可以做到这一点;它相当于 Sysinternal 非常有用的PsExec工具的 Linux 。

The last time I used Winexe was a couple of years ago, so this may have changed, but at the time, there were a couple of caveats:

我上次使用 Winexe 是在几年前,所以这可能已经改变了,但当时有几个警告:

  • Terminal handling wasn't well implemented, so typing non-alphanumeric keys to a remote command may be weird. If you're scripting, this shouldn't be an issue.
  • Like PsExec, Winexe operates by installing a service on the Windows box then telling that service to run a command. Unlike PsExec, it didn't clean the service up afterward. The installed service is harmless and doesn't run when Winexe isn't doing anything, so this is pretty much harmless.
  • 终端处理没有很好地实现,因此在远程命令中键入非字母数字键可能很奇怪。如果您正在编写脚本,这应该不是问题。
  • 与 PsExec 一样,Winexe 通过在 Windows 机器上安装服务然后告诉该服务运行命令来运行。与 PsExec 不同的是,它之后没有清理服务。已安装的服务是无害的,并且在 Winexe 不执行任何操作时不会运行,因此这几乎是无害的。

回答by angelblade

You can use Winexe

您可以使用 Winexe

$ winexe -U HOME/Administrator%'Pass123' //host 'cmd /C net stop wuauserv && net start wuauserv && echo AutoUpdates service restarted'

The password is written between ''<-- Manual dont say about this, but it work.

密码写在''<-- 手册之间没有说这个,但它可以工作。

回答by Ras Dama

Try to use

尝试使用

net rpc service list
net rpc service start
net rpc service stop

回答by Supertux

You can restart a Windows service from the Windows command line using:

您可以使用以下命令从 Windows 命令行重新启动 Windows 服务:

net stop service_name
net start service_name

You can find the Service Name by clicking on properties in the Services window.

您可以通过单击“服务”窗口中的属性找到服务名称。

That might enable you to script it.

这可能使您能够编写脚本。

回答by Guvante

The most concrete way would be to build a web service that handles the updating of the ini's and restarting of the services, but given that this is an internal solution that is likely massive overkill.

最具体的方法是构建一个 Web 服务来处理 ini 的更新和服务的重新启动,但考虑到这是一个内部解决方案,可能会过度杀伤。

回答by Domchi

I usually enable telnet, telnet to the box remotely, and use "net stop ServiceName" and "net start ServiceName".

我一般是启用telnet,远程telnet到盒子,使用“net stop ServiceName”和“net start ServiceName”。