使用 Powershell 在没有 WMI 或远程处理的情况下远程停止服务

编程入门 行业动态 更新时间:2024-10-09 12:31:02
本文介绍了使用 Powershell 在没有 WMI 或远程处理的情况下远程停止服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我遇到了这个似乎有效的衬垫:

I came across this one liner that appears to work:

stop-service -inputobject $(get-service -ComputerName remotePC -Name Spooler)

谁能解释一下原因,因为我认为除非您使用远程处理或发生在本地主机上,否则停止服务不起作用.

Can anyone explain why, because I thought stop-service didn't work unless you either used remoting or it occurred on the local host.

推荐答案

Get-Service 的输出是一个 System.ServiceProcess.ServiceController .NET 类,可以操作在远程计算机上.我不知道它是如何实现的 - 可能是 DCOM 或 WMI.一旦您从 Get-Service 获得其中之一,它就可以传递到 Stop-Service 中,它很可能只调用 Stop() 此对象上的方法.这会停止远程机器上的服务.事实上,你也可以这样做:

The output of Get-Service is a System.ServiceProcess.ServiceController .NET class that can operate on remote computers. How it accomplishes that, I don't know - probably DCOM or WMI. Once you've gotten one of these from Get-Service, it can be passed into Stop-Service which most likely just calls the Stop() method on this object. That stops the service on the remote machine. In fact, you could probably do this as well:

(get-service -ComputerName remotePC -Name Spooler).Stop()

更多推荐

使用 Powershell 在没有 WMI 或远程处理的情况下远程停止服务

本文发布于:2023-11-24 14:20:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1625564.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:情况下   Powershell   WMI

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!